Python Feature Request: Explicit variable declarations

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Apr 14 21:12:27 EDT 2007


On Sat, 14 Apr 2007 15:55:03 +0000, Dennis Lee Bieber wrote:


> Names are references to the RHS object itself.
> 
> 	a = 5
> 
> means that somewhere in memory is an integer object with the value "5";
> the name "a" is now "pasted onto" that integer object.

That's not correct, as it implies that the object 5 knows which names (if
any) it is associated with. That's not the case: objects don't know which
names point to them. 

What actually happens is that the current namespace gains an entry "a",
which points to the existing object 5. 


> 	b = a
> 
> finds the object that has the name "a" stuck to it, and sticks a second
> name "b" onto the same object. 

It most certainly does not. What it does is add another name into the
namespace, "b", and points it to the same object as "a" already points to.

We shouldn't be frightened of introducing namespaces to newbies. They
have to learn sooner or later, and they aren't hard to learn. Sometimes
over-simplifying is worse than not simplifying at all.

A namespace is just a thing in memory that the Python compiler looks up
names. They are very important to Python.



-- 
Steven.




More information about the Python-list mailing list