newb question about @property

bartc bc at freeuk.com
Thu Oct 5 07:51:03 EDT 2017


On 05/10/2017 12:29, Gregory Ewing wrote:
> bartc wrote:
>> Result? You can't just look at my 'any' class and see what fields it 
>> uses. You can't even just look at the static source code. You have to 
>> run the program to find out. And it might be different each time.
>> You can usually get a pretty good idea of what attributes a
> class has by looking at its definition. The vast majority of
> classes will either initialise their attributes in the __init__
> method or provide defaults as class variables.
>> While in theory it's possible for code to add attributes
> later after initialisation, in practice this is hardly ever
> done.

Yeah, but, like many other things in this language, there are million 
ways of doing it.
Just had a quick look, the first hit was talking about using a module 
'pyrecord'.
Another mentioned 'namedtuples'.
Another used the '__slots__' method already mentioned (remembering the 
difference between old and new classes in Python 2...)
One more uses a module 'recordtype'.
And then there is just using a normal class, where you have to look 
closely at the code to see what it's implementing. It allow ad-hoc 
fields to be created, or it may define __init__ etc.
And all with different capabilities regarding adding extra fields, 
having mutable records, initialising a record, comparing them, printing 
them, ....
Am I allowed to say that it all seems a bit of a mess?
-- 
bartc


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /