Python class strangeitude

Mr. Neutron nicktsocanos at charter.net
Sat Aug 24 21:54:22 CEST 2002


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.

Now, if I want to create two distinct objects Jimmy and Randy, is there
anyway to do this in Python from the same class? It lacks the new
statement, so I do not know how to tell Python to create a new object in
memory with it's own variables and everything.

I can prove it to you if you don't believe me! Variables in Jimmy are
Variables in Randy! Whatever I do to Randy, happens to Jimmy. They are
exactly the same Object in memory.



More information about the Python-list mailing list