Yet Another Newbie Question (YANQ)
Enrique
ecastro at cicei.ulpgc.es
Tue Feb 20 12:17:07 EST 2001
"David A." wrote:
> Hi to everyone,
>
> I am playing around with python and I have 1 quetions where I hope
> someone can help
>
> I have this problem:
>
> >>> a='a'
> >>> prt='print'
> >>> t=prt+' '+a
> >>> t
> 'print a'
>
> now when I try to:
> >>> eval(t)
> Traceback (innermost last):
> File "<pyshell#18>", line 1, in ?
> eval(t)
> File "<string>", line 1
> print a
> ^
> SyntaxError: invalid syntax
>
> can someone explain me what I am doing wrong! Why can't I use eval(print)?
> Any help is welcome!
I thinks it is a semantic confusion:
eval() evaluates an _expression_ (like i*(a+b-5))
exec() executes an _statement_ (print a, del b, import
moduleX)
Enrique
More information about the Python-list
mailing list