Bug or feature?

Fredrik Lundh fredrik at pythonware.com
Fri May 14 09:16:01 EDT 1999


> > So, if I initialize an array variable within the "class scope" (for
> > want of knowing the proper word) by simple assignment, this same array
> > is shared between *all* instances of the class.  If I do the same 
> > initialization within a class method (like __init__), then each
> > instance has its own copy of the array.  I like the second case much
> > better... having the array shared between all instances just strikes
> > me as wrong.

just pretend that you simply cannot define variables in the
class namespace!  if you initialize your instance variables in
the __init__ method (like everyone else already does), things
will work exactly as you expect.  

...

could anyone tell me which beginner's document that says
that Python has class variables, and that using them is a good
idea?  especially for mutable data types?

given the number of recent posts on this topic, I'm beginning
to suspect that we have a SERIOUS documentation problem
here...

maybe some of the recent posters could shed some light on
this: where did you learn about class variables in the first
place?  and if you used them in an earlier life, what made
you start using them in Python?

</F>





More information about the Python-list mailing list