eval() in python

X

Xah Lee

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
(e-mail address removed)
∑ http://xahlee.org/
 
H

harold fellermann

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?

Python 2.4 (#1, Dec 30 2004, 08:00:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
- harold -
 
M

Martin Blume

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.Traceback (most recent call last):

HTH
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top