On 12/4/06, Josiah Carlson <jcarlson at uci.edu> 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 >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20061207/372b3526/attachment.html
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4