Handling Property and internal ('__') attribute inheritance and creation

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Aug 19 13:38:09 CEST 2008


Fredrik Lundh a écrit :
> Eric Brunel wrote:
> 
>> To add to what others have already said, it is not only 'just extra 
>> work', it is also quite dangerous. See:
>>
>> class A(object):
>>   children = []
> 
> the OP is aware of that, of course:
> 
>  > I set anything that is constant but anything variable is set again in
>  > __init__()
> 
> as long as if you're aware of the issues involved (which you should be 
> if you're using Python professionally), using class-level attributes is 
> a perfectly valid Python style.

Using class attributes is perfectly valid Python style, indeed. But in 
this case - ie: using class attributes as a pseudo-declaration of 
instance attributes -, I would not call this good style : it's a waste 
of time, a violation of DRY, and a potential source of confusion for the 
class's users / maintainers.



More information about the Python-list mailing list