[Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perl
Alexey Borzenkov
snaury at gmail.com
Thu Dec 7 21:01:46 CET 2006
More information about the Python-Dev mailing list
Thu Dec 7 21:01:46 CET 2006
- Previous message: [Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perl
- Next message: [Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perl
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perl
- Next message: [Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perl
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list