Tkinter callback arguments
Diez B. Roggisch
deets at nospam.web.de
Mon Nov 2 08:07:38 EST 2009
Alf P. Steinbach wrote:
> * Peter Otten:
>> Alf P. Steinbach wrote:
>>
>>>> for x in range(0,3):
>>>> Button(......, command=lambda x=x: function(x))
>>> An alternative reusable alternative is to create a button-with-id class.
>>>
>>> This is my very first Python class so I'm guessing that there are all
>>> sorts of issues, in particular naming conventions.
>>
>> Pseudo-private attributes
>
> That means there is some way of making attributes private?
No, it means that in Python we are consenting adults, and either respect
attributes with a leading underscore as private - or willfully chose to
*not* do that because of good reasons.
And the double-underscore is used against name-clashes, not for
enhanced "privacy".
>>, javaesque getter methods,
>
> What do you mean by that?
>
> What I associate with Java getter method is mainly the "get" prefix, for
> Java introspection.
You have an attribute id, whatfor do you need a method id? If at some point
this id becomes a computed value - you introduce a property
And that's what Peter meant with "javanesque" - the exact reason why in java
everything is wrapped in getters/setters is that the language lacks a
property-mechanism, so to present a consistent interface over several
iterations of the code, one has to introduce them for every single
attribute - regardless of their future destiny.
>
>> unidiomatic None-checks
>
> What's the idiomatic Python way for an optional thing?
None is a singleton, so the idiomatic check is for object identity:
foo = None
foo is None
Diez
More information about the Python-list
mailing list