Bug? exec converts '\n' to newline in docstrings!?

Diez B. Roggisch deets at nospam.web.de
Mon Jul 30 17:45:12 CEST 2007


Edward K Ream wrote:

> It looks like both exec and execfile are converting "\n" to an actual
> newline
> in docstrings!
> 
> Start idle:
> 
> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
> on win32
> [rest of signon deleted]
> 
>>>> s = '''\
> strings = 'abc'.split("\n")
> '''
>>>> print s
> strings = 'abc'.split("
> ")
> 
> I see this in my own calls to exec and execfile.  Is this a bug or am I
> missing something?

AFAIK docstrings are nothing special. So \-escaping is of course available,
as it's an important feature for strings in general.

For the case at hand, 

strings = 'abc'.split("\\n")

might help.

Diez



More information about the Python-list mailing list