python variable assignement

Carsten Haese carsten at uniqsys.com
Mon Sep 24 06:35:34 EDT 2007


On Mon, 2007-09-24 at 10:13 +0000, mihai wrote:
> I work at an application witch has embeded python.
> 
> We have an python type X.
> 
> # a != b
> 
> a = b # at this point both variables have the same value

Not quite. At this point, 'a' and 'b' are names in the local namespace
that refer to the same object.

> b = select_other()

Now 'b' becomes a reference to the object returned by select_other().
Presumably that's a different object than the one it referred to before.
'a' still refers to the same object it referred to before.

> # steel the same values but both have the new value of b

No, the code you showed us wouldn't behave this way.

> What might be the cause for this behavior?

What behavior?

>  The type of a and b
> variable is the same,
> and is defined using PyTypeObject structure.

That doesn't matter. (Variable) Names don't have types. Objects have
types, and a name can refer to an object of any type. See
http://effbot.org/zone/python-objects.htm .

> I hope I was explicit.

Unfortunately, you weren't. If the above explanations didn't help you,
please explain what you want to achieve, show us your actual code and
what you expect it to do, and tell us what it's doing instead.

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list