String2List: odd function

Bernhard Herzog herzog at online.de
Thu Jul 29 05:55:47 EDT 1999


"Fredrik Lundh" <fredrik at pythonware.com> writes:

> well, last time I checked, eval didn't accept statements.

True, but if the eval'ed code has access to the normal builtins, you can
sneak statements into the expression with compile:

>>> eval('''eval(compile("for i in range(10): print i", "", "exec"))''')
0
1
2
3
4
5
6
7
8
9
>>> 


-- 
Bernhard Herzog	  | Sketch, a python based drawing program
herzog at online.de  | http://www.online.de/home/sketch/




More information about the Python-list mailing list