ANN: pkalk, and problems with "exec foo in g,v"

Gerson Kurz gerson.kurz at t-online.de
Tue Dec 24 15:02:39 EST 2002


Ah, Christmas is over, Pythontime again!

Announcing pkalk: a (wx)Python powered kalkulator, that evaluates
expressions as you type them. Great for approximating results and
stuff. Freeware and all that: 

http://p-nand-q.com/e/pkalk.html

Sorry, no linux version yet, I'm stuck with my 2k box this week. 

I have this problem though:

ActivePython 2.2.2 Build 224 (ActiveState Corp.) based on
Python 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from math import *
>>> a = lambda x:sin(x)
>>> print a(2)
0.909297426826
>>> g,v={}, {}
>>> exec "from math import *" in g, v
>>> exec "a = lambda x:sin(x)" in g, v
>>> exec "sin(2)" in g, v
>>> exec "a(2)" in g, v
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 1, in ?
  File "<string>", line 1, in <lambda>
NameError: global name 'sin' is not defined

So, my problem is this: I'm using "exec foo in g,v" for statement
evaluation. I can import math, and conveniently use the math stuff
(its a calculator, after all). I cannot, however, define a local
lambda that uses the "global" scope in g,v. Is that a bug or a
feature?



More information about the Python-list mailing list