On Tue, 29 Jul 2008 03:26:45 +0000, Peter Teuben wrote:

> if I define a simple string code, with the following contents:
> 
> import math
> def foo(x):
>    return math.sqrt(x)
> 
> and i run it using exec(code) in python, math is not known.


Works for me.


>>> code = """import math
... def foo(x):
...     return math.sqrt(x)
... """
>>>
>>> exec code 
>>> foo(25)
5.0

By the way, exec is a statement, not a function, so you don't need the 
brackets.



-- 
Steven
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to