On 12/4/06, Josiah Carlson <[EMAIL PROTECTED]> wrote:
With the proper mapping, this is trivial...
class namelookup:
[...snip...]
foo = foo()
>>> print "%(foo.b)i + %(foo.a)i"%namelookup(locals())
2 + 1
>>>
It can even be simpler and more powerful:
class evallookup:
def __init__(self, nsg, nsl):
self.nsg = nsg
self.nsl = nsl
def __getitem__(self, name):
return eval(name, self.nsg, self.nsl)
class foo:
a = 1
b = 2
print "%(foo.a)i + %(foo.b)i = %(foo.a + foo.b)i" %
evallookup(globals(), locals())
1 + 2 = 3
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com