Reading newlines from a text file
Diez B. Roggisch
deets_noospaam at web.de
Sat Feb 28 19:13:54 EST 2004
> Also, I notice that you have two backslashes before each n in
> "\\ntoerichte\\nlogik\\nboeser\\nkobold\n". Why is there a need for 2
> backslashes -would not one have done the trick?
Two backslashes escape the bacslash - otherwise the text in tmp.txt would
have contained _newlines_, not the \n-escape sequence you wanted. Test
this:
print "foo\nbar"
foo
bar
print "foo\\nbar"
foo\nbar
And the encoding argument is in codecs.open, not in builtin open - so you'll
find it documented in the codecs-module.
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list