[Python-ideas] proposal to add rowexpr as a keyword
Steve Howell
showell30 at yahoo.com
Thu May 31 02:29:20 CEST 2007
--- Stargaming <stargaming at gmail.com> wrote:
>
> That's a harder one, indeed. Perhaps, nothing should
> be dereferenced (at
> ``compile'' time, don't know if that's a valid term
> in CPython's
> interpreter chain tho), as it is in a
> lambda-expression.
>
Just tried a few examples, almost everything
interesting happens at runtime:
======== PYTHON 2.3
Valid Python:
salary = 2
print (lambda: salary)() # prints 2
---
Valid, but useless, Python (no errors)
lambda: salary
---
Run-time error:
x = lambda: salary
x()
NameError: global name 'salary' is not defined
---
Run-time error:
x = lambda: convert_to_euros(salary)
x()
NameError: global name 'convert_to_euros' is not
defined
---
Run-time error:
def convert_to_euros(amt): return amt.impossible
salary = None
x = lambda: convert_to_euros(salary)
x()
AttributeError: 'NoneType' object has no attribute
'impossible'
---
Run-time error:
def convert_to_euros(amt): raise 'this does not get
here'
row = None
x = lambda row: convert_to_euros(row['salary'])
x(row)
TypeError: 'NoneType' object is unsubscriptable
======= 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
---
Run-time error:
def convert_to_euros(amt): raise 'this does not get
here'
row = None
x = rowexpr: convert_to_euros(salary)
x(row)
TypeError: 'NoneType' object is unsubscriptable
---
____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/
More information about the Python-ideas
mailing list