eval() in python

Martin Blume mblume at socha.net
Tue Jun 21 11:09:36 EDT 2005


"Xah Lee" schrieb
>
> perhaps i'm tired, but why can't i run:
>
> t='m=3'
> print eval(t)
>
Perhaps you didn't read the documentation? :-)
Perhaps you didn't try hard enough?


C:\WINNT>c:\programme\python\python
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> t='m=3'
>>> m
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'm' is not defined
>>> exec(t)
>>> m
3
>>>

HTH
Martin





More information about the Python-list mailing list