Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread Gabriel Genellina
En Wed, 05 Sep 2007 11:45:11 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribi�: > Thank you for the explanation > > It seems that python behaves different for variables created in the > toplevel namespace, versus deeper namespaces. Yes. Older Python versions had only two scopes: local and g

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread Peter Otten
Am Wed, 05 Sep 2007 14:45:11 + schrieb [EMAIL PROTECTED]: > So now get back to my exec code in the previous post. > The exec applies a mixture of both rules > 1. The exec looks at its namespace to apply the rule for globals(). > Since I'm not at top-level, variables are not auto-populated in t

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread [EMAIL PROTECTED]
Hi Thank you for the explanation It seems that python behaves different for variables created in the toplevel namespace, versus deeper namespaces. CODE: def g(): a=2 print "a in LOC:",locals().has_key('a') print "a in GLO:",globals().has_key('a') def f(): print "a in LOC:",locals().

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread Peter Otten
Am Wed, 05 Sep 2007 13:12:24 + schrieb [EMAIL PROTECTED]: > I am completely puzzled why the following exec code does not work: > > mycode = "import math\ndef f(y):\nprint math.floor(y)\nf(3.14)" > def execute(): > exec mycode > execute() > > > I get the error: > > [EMAIL PROTECTED]

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread Daniel Larsson
On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hello > > I am completely puzzled why the following exec code does not work: > > mycode = "import math\ndef f(y):\nprint math.floor(y)\nf(3.14)" > def execute(): > exec mycode > execute() > > > I get the error: > > [EMAIL PROTECTED

python exec behaves inconsistent with respect to module imports

2007-09-05 Thread [EMAIL PROTECTED]
Hello I am completely puzzled why the following exec code does not work: mycode = "import math\ndef f(y):\nprint math.floor(y)\nf(3.14)" def execute(): exec mycode execute() I get the error: [EMAIL PROTECTED]:/opt/qbase# python error1.py Traceback (most recent call last): File "error