A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-December/070277.html below:

[Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perl

[Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perl [Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perlAlexey Borzenkov snaury at gmail.com
Thu Dec 7 21:01:46 CET 2006
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 
More information about the Python-Dev mailing list

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