[Tutor] bug in eval() ? or doing something forbidden ?
Steckel, Ralf
Ralf.Steckel at AtosOrigin.com
Sun May 9 23:53:26 EDT 2004
Dear Tutor,
I'm trying to get the string representation of a string variable containing
the unicode representation of a string via eval(). This works fine as long
as I don't have any ' or " preceeded with a backslash in the representation.
Is there a bug in eval() or am I doing something wrong?
>From the first statement in the snapshot of Idle (see below), I would expect
that eval() should processes backslashes in the representation of unicode
strings and ' or " preceeded by a backslash is a valid token for an unicode
string.
Thanks for any help,
Ralf
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license()" for more information.
****************************************************************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet.
****************************************************************
IDLE 1.0
>>> print u'\'abcd\"'
'abcd"
>>> a="u'\'abcd\"'"
>>> print eval(a)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in -toplevel-
print eval(a)
File "<string>", line 1
u''abcd"'
^
SyntaxError: invalid syntax
>>>
>>> a="u'\'abcd\''"
>>> print eval(a)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in -toplevel-
print eval(a)
File "<string>", line 1
u''abcd''
^
SyntaxError: invalid syntax
>>>
More information about the Tutor
mailing list