About the use of **args

Jacek Generowicz jacek.generowicz at cern.ch
Thu Dec 11 08:03:36 EST 2003


Zunbeltz Izaola <zunbeltz at wm.lc.ehu.es.XXX> writes:

[snip]

> 3) If when setting some attribute there is necesary to have side
>    effects, it can be achive defining __setattr__ and doing the right
>    thing depend on the attribute. (It is possible to raise an
>    exception when the attribute is not in a list/dictionary of usable
>    attributes, to prevent typos and such kind of errors)
> 
> 4) __getattr__ can be defined to deal with undefined attributes. For
>    example it can handle in different way the attributes in a list of
>    permited attributes (see point 3)
> 
> 5) attributes that are computed in the fly, can be get like normal
>    attributes using "property" (property is new in 2.3 or 2.2?)

[snip]

> Are those ideas correct?

Pretty much.

Properties are available in 2.2. They only work on new style classes.

Just about anything that can be done with properties can be done with
__setattr__ &co, but I think that properties are generally preferred,
if available.




More information about the Python-list mailing list