How to do * and & C-lang. operations in Python?

Terry Reedy tjreedy at home.com
Thu Sep 20 17:55:14 EDT 2001


"Toni Gaya" <gaya at infomail.lacaixa.es> wrote in message
news:61f6bfa8.0109200846.77af2300 at posting.google.com...
> I have a variable defined on one module, and want to use _exactly_
the
> same variable in other module. Example:

Python does not have variables in the sense you are using it here (the
'C' sense).  The closest are slot in a list.

>
> module1:
> a = 1
>
> module 2:
> import module1
> a = module1.a
> Now, I have module1.a value in a, not a reference to module1.a in a
> (module2.a).
> Assignaments are done by 'value', not by 'reference'.

No, No, No!  Not in Python.

In C, a name represents a fixed block of linear memory with an address
and size.
'a = expression' puts the value of the expression into that block.
(Which raises concerns, nonexistent in Python, about size/type
mismatch.)

In Python, a name is just a name -- period -- with no connection to
'memory'.
'a = expression' assigns the name to an object with the value of the
expression by associating the name with a reference to that object in
a namespace (which may or may not be a dictionary).  Any name can be
bound to any object at any time.  Note that assignment is, in a sense,
from left to right rather than from right to left as in most
languages.

Terry J. Reedy







More information about the Python-list mailing list