A TYPICAL NEWBIE MISTAKE?
Frank V. Castellucci
frankc at colconsulting.com
Mon May 15 20:34:26 EDT 2000
François Pinard wrote:
>
> Courageous <jkraska1 at san.rr.com> writes:
>
> > My key point was that it's easy to get confused when assignment to
> > self.attribute overrides the common class attribute. [...]
>
> The question was surely interesting. In any case, from my own experience, I
> found out that common class attributes (besides the class methods themselves)
> are not much used in practice. There are only three cases where I found
> them useful:
>
> * To get speedier __init__ by presetting some slow-to-compute parameters,
> when these are independent of actual __init__ parameters, since the
> computation occurs once when the class gets defined.
>
> * To build overall dictionaries or list of all instances of a class, by
> presetting the dictionary to empty as a common attribute, and having each
> __init__ to register the newly created instance to that dictionary.
>
> * To ease the writing and access of some dictionaries, using classes usually
> having no methods; my favourite is a `run' class which holds all the global
> option values, and nothing else, which I preset with default option values.
>
> --
> François Pinard http://www.iro.umontreal.ca/~pinard
Add to that instrumentation, singleton objects, and framework handlers.
--
Frank V. Castellucci
http://corelinux.sourceforge.net
OOA/OOD/C++ Standards and Guidelines for Linux
http://PythPat.sourceforge.net
Pythons Pattern Package
More information about the Python-list
mailing list