Peter Teuben wrote:
>
> if I define a simple string code, with the following contents:
>
> import math
> def foo(x):
>return math.sqrt(x)
The
import math
statement puts 'math' in the local namespace, and foo looks it up in the
global namespace. This can only work when these namespaces a
On Tue, 29 Jul 2008 03:26:45 +, 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(
Peter Teuben wrote:
if I define a simple string code, with the following contents:
import math
def foo(x):
return math.sqrt(x)
What? You have not told us something important here. First, that code
won't fail because it does not even execute the function foo -- it just
defines it.Sec
Peter Teuben wrote:
if I define a simple string code, with the following contents:
import math
def foo(x):
return math.sqrt(x)
What? You have not told us something important here. First, that code
won't fail because it does not even execute the function foo -- it just
defines it.Sec
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. But when I
recode the string as:
def foo(x):
import math
return math.sqrt(x)
it works fine. That seemed like an inconsis