Tkinter callback arguments

Alf P. Steinbach alfps at start.no
Mon Nov 2 09:12:31 EST 2009


* Diez B. Roggisch:
> 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.

Hm. But thanks! That's very useful information  --  now I'll not be going on a 
wild goose chase!


> 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.

Thanks again for useful information.

Also Peter mentioned this about changing simple attributes into properties at 
later time, so that seems to at least not be unheard of in Python?

Your comment about "computed" makes it more clear what that's all about. Also 
Bertrand Meyer (Eiffel language creator) had idea like that, he called it 
"referential transparency". But I think when Python has this nice property 
mechanism, why do people change direct data attributes into properties and not 
the other way around or not at all, I mean using only properties for logical 
data attributes  --  e.g. assuring correctness first via read-only property?


>>> 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

Again, thanks, that helps me understand the rationale. Although not completely. 
But there is a connection...


Cheers,

- Alf



More information about the Python-list mailing list