Finding the instance reference of an object [long and probably boring]

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Nov 8 05:21:07 CET 2008


On Fri, 07 Nov 2008 13:05:16 -0700, Joe Strout wrote:

> In Python, AFAICT, there is only one type, the object reference.  So,
> the type of every variable is 'reference', and each one contains a
> reference.

This is wrong. If we take "variable" to mean "name", then Python names do 
not have types. But *objects* have types, and there are many of them:

>>> a = 23; type(a)
<type 'int'>
>>> a = "foo"; type(a)
<type 'str'>
>>> a = []; type(a)
<type 'list'>

But a name that isn't bound to an object doesn't have a type:

>>> del a; type(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined

The type information is associated with the object, not with the name.

It is possible that, in the C implementation, there is a C-type 
'reference' and all(?) C variables relating to the implementation of 
namespaces have that type. Possibly. But even if true, that's the wrong 
level of description.


-- 
Steven



More information about the Python-list mailing list