Ooops!

Mr. Neutron nicktsocanos at charter.net
Sat Aug 24 23:16:33 CEST 2002


On Sat, 24 Aug 2002 16:07:50 -0400, Erik Max Francis wrote:

> "Mr. Neutron" wrote:
>> 
>> Nope classes are not the same thing in memory. Somehow my variable is
>> being shared between both objects.
> 
> Note that all "variables" in Python are really just bindings, and all
> the assignment statement does is rebind names.  So when you have
> multiple bindings to the same mutable object, changes in one will affect
> the other:
> 
>>>> a = [1, 2, 3]
>>>> b = a
>>>> b.append(4)
>>>> a
> [1, 2, 3, 4]
> 
> If you want a separate copy, you will have to do so explicitly.
> 
Well I found the problem. this is how I see it

Suppose I have a Python Class
	
	class MyClass(base):
		class_inside = some_class(...)

		...


	class_inside is actually like  a static varaible in C++

	class MyClass {
		static class_inside some_class;

		...


	I was under the assumption that class_inside was a public
	variable that was instantiated with every new class. But my
	observation has proven it is not true every class with have
	a reference to class_inside ( I can show actual code that
	proves this...)


Thanks



More information about the Python-list mailing list