re.sub
Tim Chase
python.list at tim.thechases.com
Tue Oct 16 14:20:59 EDT 2007
> Even stranger
>
> >>> re.sub('a', '\\n','bab')
> 'b\nb'
> >>> print re.sub('a', '\\n','bab')
> b
> b
That's to be expected. When not using a print statement, the raw
evaluation prints the representation of the object. In this
case, the representation is 'b\nb'. When you use the print
statement, it actually prints the characters rather than their
representations. No need to mess with re.sub() to get the behavior:
>>> s = 'a\nb'
>>> s
'a\nb'
>>> print s
a
b
>>> print repr(s)
'a\nb'
-tkc
More information about the Python-list
mailing list