title: YAML adds a second backslash, python prints correctly but does not write to file correctly
body: <p>The code is reading YAML from a document, which I then load into an object. I am now encountering issues where a second backslash is added to regex code, so instead of \ I get \\. in a list that can contain several regex entries, this is the correct code:</p>
  <pre><code>['\/?r\/']
  </code></pre>
  <p>And I understand why it <em>shows</em> it this way in python, because when using print() it DOES print it correctly. However when attempting to write a block of text this is into a file with open() and write, it is saved as</p>
  <pre><code>['\\/?r\\/']
  </code></pre>
  <p>which would render the regex code invalid for the next system to read.</p>
  <p>The following code will reproduce this</p>
  <pre class="lang-py prettyprint-override"><code>    reg = &quot;regex: ['\/?r\/']&quot;
      yamlreg = yaml.load(reg, Loader=yaml.BaseLoader)
      regexvalue = yamlreg['regex']
      rule = f&quot;    regex: {regexvalue}&quot;
      with open(&quot;test.txt&quot;, &quot;w+&quot;) as b:
          b.write(rule)
  </code></pre>
  <p>the reg value will usually have more options which is not needed to show. Finally the object everything is ordered into requires special formatting, hence the leading spaces in the string. regexvalue will print in python as \, but will be written to file as \\</p>