Re: problem with namespaces using eval and exec

2006-05-17 Thread Jens
Thanks a lot, that works for me. -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with namespaces using eval and exec

2006-05-16 Thread Peter Otten
Jens wrote: > has anyone an idea why the following code does not work. > s = """ > def a(n): > return n*n > def b(t): > return a(t) > """ > ns = {} > exec(s, {}, ns) Here you are providing a local namespace into which all toplevel names (a and b) are inserted. > eval("b(2)", ns, {}) Here

Re: problem with namespaces using eval and exec

2006-05-16 Thread Maric Michaud
Le Mardi 16 Mai 2006 11:05, Jens a écrit : > s = """ > def a(n): >   return n*n > > > def b(t): >   return a(t) > """ > > > ns = {} > exec(s, {}, ns) > eval("b(2)", ns, {}) you passed an empty globals dictionnary to the eval func (the local one is not in the scope of b defintion) try this : exec

problem with namespaces using eval and exec

2006-05-16 Thread Jens
Hi, has anyone an idea why the following code does not work. s = """ def a(n): return n*n def b(t): return a(t) """ ns = {} exec(s, {}, ns) eval("b(2)", ns, {}) executing this script raises an exception (NameError: global name 'a' is not defined) in the last line. Hope for your help