Doctest Involving Escape Characters
问题 Have a function fix(), as a helper function to an output function which writes strings to a text file. def fix(line): """ returns the corrected line, with all apostrophes prefixed by an escape character >>> fix('DOUG\'S') 'DOUG\\\'S' """ if '\'' in line: return line.replace('\'', '\\\'') return line Turning on doctests, I get the following error: Failed example: fix('DOUG'S') Exception raised: Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7