string to integer problem

Gerrit gerrit at nl.linux.org
Sun Feb 8 12:37:32 EST 2004


Lol McBride wrote:
> On Sun, 08 Feb 2004 18:00:11 +0100, Diez B. Roggisch wrote:
> >>>> s = '(1,10,23,33,35,48)'
> >>>> t = eval(s)
> >>>> print t
> > (1,10,23,33,35,48)
> Hi,
> thanks for this it worked a treat but I don't understand how - even after
> reading the docs for the eval() builtin function.Could you explain what's
> going on (in fairly simple terms as well - I'm a programmer for fun not
> cause it's my job)

Passing a string to 'eval' is equal in having it as a part of an
expression, for example as having in at the right side of an assignment
operator (=), except for the quotes. The string returned happens to be
valid Python syntax: numbers seperated by comma's with ( and ) around it
create a tuple. It is valid to simply onter (1,2,3) at the Python
interactive interpreter: this is why it is valid to pass '(1,2,3)' to
eval. The result is the same.

Hope this helps,
yours,
Gerrit.

-- 
PrePEP: Builtin path type
    http://people.nl.linux.org/~gerrit/creaties/path/pep-xxxx.html
Asperger's Syndrome - a personal approach:
	http://people.nl.linux.org/~gerrit/english/




More information about the Python-list mailing list