Raw String Output
Chris Liechti
cliechti at gmx.net
Thu Jun 20 19:27:10 EDT 2002
"mike" <gringro1 at umbc.edu> wrote in news:aetnkf$tot$1 at news.umbc.edu:
> If I have a string variable with the value '\n' how do I output it to
> a file with the value of '\012' instead ?
i assume that its clear to you that '\n' == '\012' so i guess you want the
string r'\012' in the file and not the newline character?!?
then you must do it by hand, i think. this one replaces all characters < 32
with their octal value:
>>> print ''.join([ c>=' ' and c or '\\%03o' % ord(c) for c in 'hello\n'])
hello\012
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list