[Kde-bindings] Python Qt4 Newbie

Ruben Fonseca rf at 7syntax.com
Thu Aug 21 09:50:33 UTC 2008


On Wed, 2008-08-20 at 16:24 -0300, Lauro Moura wrote:
> On Wed, Aug 20, 2008 at 12:08 PM, Ruben Fonseca <rf at 7syntax.com> wrote:
> > regardless the button I click... So I'm guessing something's wrong with
> > my lambda function.
> >
> > What's the best way of solving this particular problem in Python?
> 
> You guessed right, as the lambda is told to 'call button_clicked with
> the object identified by the name button *at the time of the call* as
> argument'. So, after the loop the name button is still bound to the
> last item of that list, thus being passed to each slot.

So I guess I've been caught by the snake :)

> >>> x = lambda : a*4
> >>> x()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 1, in <lambda>
> NameError: global name 'a' is not defined
> >>> a = 3
> >>> x()
> 12

Isn't it possible to define real anonymous functions in Python, without
this lexical/binding thing?

Ruben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20080821/9bbe7fad/attachment-0001.sig>


More information about the Kde-bindings mailing list