Lambda added to release 2.2 ?
Fabien Hénon
ffjhenon at club-internet.fr
Sun Apr 14 12:17:47 EDT 2002
When I start my python script, here is what I get on the console from
Linux (Python 2.1) :
a26.py:51: SyntaxWarning: local name 'self' in '__init__' shadows use of
'self' as global in nested scope 'lambda'
def __init__(self, master):
When I use the lines below :
> insertmenumaterial.add_command(label="interior", command = lambda :
self.insert_example("interior.txt"))
> def insert_example(self,nom):
> chemin="insert"
> contents=fd.read()
> self.text.insert(INSERT,contents)
> fd.close()
I get the following message :
>>> Exception in Tkinter callback
>>> Traceback (most recent call last):
>>> File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 1285, in
__call__
>>> return apply(self.func, args)
>>> File "a26.py", line 219, in <lambda>
>>> insertmenumaterial.add_command(label="interior", command =
lambda : self.insert_example("interior.txt"))
>>> NameError: global name 'self' is not defined
I don't have any problem under W2000 ( Python 2.2)
Is lambda function a new add-on to 2.2 ? I thought it was added ages
ago.
Thanks
More information about the Python-list
mailing list