[Python-ideas] proposal to add rowexpr as a keyword
Steven Bethard
steven.bethard at gmail.com
Thu May 31 04:22:01 CEST 2007
On 5/30/07, Steve Howell <showell30 at yahoo.com> wrote:
> ======= THEORETICAL
>
> Valid Python:
>
> row = {'salary': 50000}
> def convert_to_euros(amt): return amt / 2
> x = rowexpr: convert_to_euros(salary)
> print x(row) # prints 25000
>>> def rowexpr(expr):
... def evaluate(row):
... d = dict(row)
... d.update(globals())
... exec '__result__ = ' + expr in d
... return d['__result__']
... return evaluate
...
>>> def convert_to_euros(amt):
... return amt / 2
...
>>> x = rowexpr('convert_to_euros(salary)')
>>> row = dict(salary=50000)
>>> print x(row)
25000
STeVe
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
More information about the Python-ideas
mailing list