eval() in python
Xah Lee
xah at xahlee.org
Tue Jun 21 07:32:19 EDT 2005
is it possible to eval a string like the following?
m='''
i0=[0,1]
i1=[2,3]
i2=[4,'a']
h0=[]
for j0 in i0:
h1=[]
for j1 in i1:
h2=[]
for j2 in i2:
h2.append(f(j0,j1,j2))
h1.append( h2[:] )
h0.append( h1[:] )
return h0'''
perhaps i'm tired, but why can't i run:
t='m=3'
print eval(t)
the doc seems to suggest that eval is only for expressions... it says
uses exec for statements, but i don't seem to see a exec function?
Xah
xah at xahlee.org
∑ http://xahlee.org/
More information about the Python-list
mailing list