Seite 1 von 1

Zeilenumbruch in doctest löst Fehler aus

Verfasst: Freitag 9. Juli 2010, 09:41
von derdon
Guten Morgen,

ich habe eine wahrscheinlich sehr einfach Frage für euch: Warum schlägt der folgende doctest fehl? Pythoncode: http://paste.pocoo.org/show/235359/ und Ausgabe: http://paste.pocoo.org/show/235358/

Wie man in der Ausgabe in den Zeilen 7 und 8 sieht, wurde aus dem \n ein "echter Zeilenumbruch" gemacht, wohingegen der \n in Zeile 10 so blieb.

Re: Zeilenumbruch in doctest löst Fehler aus

Verfasst: Freitag 9. Juli 2010, 10:21
von derdon
Problem ist gelöst danke RTFM :)

Lösung: http://paste.pocoo.org/compare/235376/235359/
http://docs.python.org/library/doctest.html#how-are-docstring-examples-recognized hat geschrieben: If you continue a line via backslashing in an interactive session, or for any other reason use a backslash, you should use a raw docstring, which will preserve your backslashes exactly as you type them […] Otherwise, the backslash will be interpreted as part of the string. For example, the “\” above would be interpreted as a newline character. Alternatively, you can double each backslash in the doctest version (and not use a raw string)

Edit: Cool, Links als Autor eines Zitats funktionieren tatsächlich. Sehr praktisch :)