title: How to deal with Hex values in YAML using both Go and Python?
body: <p>I have this simple following program:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  
      yaml "gopkg.in/yaml.v2"
  )
  
  type Test struct {
      SomeStringWithQuotes string `yaml:"someStringWithQuotes"`
      SomeString           string `yaml:"someString"`
      SomeHexValue         string `yaml:"someHexValue"`
  }
  
  func main() {
      t := Test{
          SomeStringWithQuotes: "\"Hello World\"",
          SomeString:           "Hello World",
          SomeHexValue:         "0xDef9C64256DeE61ebf5B212238df11C7E532e3B7",
      }
      yamlBytes, _ := yaml.Marshal(t)
      fmt.Print(string(yamlBytes))
  }
  </code></pre>
  
  <p>This prints the following and obviously demonstrates that Go makes decisions on when to quote a string or not:</p>
  
  <pre><code>someStringWithQuotes: '"Hello World"'
  someString: Hello World
  someHexValue: 0xDef9C64256DeE61ebf5B212238df11C7E532e3B7
  </code></pre>
  
  <p>However, when I try to read this YAML using the following Python script:</p>
  
  <pre><code>import yaml
  
  yaml_str = """
  someStringWithQuotes: '"Hello World"'
  someString: Hello World
  someHexValue: 0xDef9C64256DeE61ebf5B212238df11C7E532e3B7
  """
  
  print(yaml.load(yaml_str))
  </code></pre>
  
  <p>It parses the Hex value as an integer. If I now serialize back to YAML using this code:</p>
  
  <pre><code>import yaml
  import sys
  
  yaml_str = """
  someStringWithQuotes: '"Hello World"'
  someString: Hello World
  someHexValue: 0xDef9C64256DeE61ebf5B212238df11C7E532e3B7
  """
  
  print(yaml.dump(yaml.load(yaml_str)))
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>someHexValue: 1272966107484048169783147972546098614451903325111
  someString: Hello World
  someStringWithQuotes: '"Hello World"'
  </code></pre>
  
  <p>How can I best make sure that the Hex format is preserved? Unfortunately, I personally don't have any influence on the code on the Go side (but a Go-side solution is still welcome for other people who try to do similar things).</p>