Python class strangeitude

Terry Reedy tjreedy at udel.edu
Sun Aug 25 02:48:59 EDT 2002


"Mr. Neutron" <nicktsocanos at charter.net> wrote in message
news:pan.2002.08.24.15.54.21.956955.4676 at charter.net...
> Hi,
> I have discovered a strange thing about Python. I have a class,
we'll
> call it MyClass. MyClass is derived from MyClassBase.
>
> Now I do this
>
> Jimmy = MyClass(...)
> ...
>
> Randy = MyClass(...)
>
>
> And guess what? Jimmy and Randy are the same darn thing in memory! I
was
> assuming that classes in Python were like in C++ in the way they
behave.

If you write a class as a singleton class, this is the normal and
usually desired behavior.  Hard to do by accident though....

tjr






More information about the Python-list mailing list