DiPierro, Massimo MDiPierro at
Tue Oct 16 20:17:36 CEST 2007

It is the fisrt line that is wrong, the second follows from the first, I agree.

From: Tim Chase [python.list at]
Sent: Tuesday, October 16, 2007 1:20 PM
To: DiPierro, Massimo
Cc: python-list at; Berthiaume, Andre
Subject: Re: re.sub

> 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
   >>> print s
   >>> print repr(s)


More information about the Python-list mailing list