title: Doctest Involving Escape Characters
body: <p>Have a function fix(), as a helper function to an output function which writes strings to a text file. </p>
  
  <pre><code>def fix(line):
      """
      returns the corrected line, with all apostrophes prefixed by an escape character
  
      &gt;&gt;&gt; fix('DOUG\'S')
      'DOUG\\\'S'
  
      """
      if '\'' in line:
          return line.replace('\'', '\\\'')
      return line
  </code></pre>
  
  <p>Turning on doctests, I get the following error:</p>
  
  <pre><code>Failed example:
      fix('DOUG'S')
  Exception raised:
      Traceback (most recent call last):
        File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 1254, in __run
          compileflags, 1) in test.globs
        File "&lt;doctest convert.fix[0]&gt;", line 1
          fix('DOUG'S')
                    ^
  </code></pre>
  
  <p>No matter what combination of \ and 's I use, the doctest doesn't seem to to want to work, even though the function itself works perfectly. Have a suspicion that it is a result of the doctest being in a block comment, but any tips to resolve this.</p>