problems with the types module

Terry Reedy tjreedy at udel.edu
Wed Dec 11 21:31:42 EST 2002


"David Necas (Yeti)" <yeti at physics.muni.cz> wrote in message
news:mailman.1039641699.19820.python-list at python.org...
> IIUC type(object) doesn't return type of the object, as we
> all thought and as is written everywhere.

Huh?  As I understand and perceive by experiment, yes it does.

>>> a=1
>>> at=type(a)
>>> at
<type 'int'>
>>> type(at)
<type 'type'>

As far as I can tell, type(object) returns the instance of the type
type that is the type of the object.  Or did you mean something else?

>  The underlying
> object is unique and can have only one type (and it has not
> a name, since it's just some thing in memory).

If you are saying that there is only one instance of type type for
each type (and we would not want more), you are correct.

>>> id(type(a))
504009944
>>> id(type(2))
504009944
>>> type(int)
<type 'type'>
>>> id(int)
504009944

> type(object) in fact returns type of the reference `object'
> to the unnamed object, and this is of course contextually
> dependent.

I am not sure what you are saying above.  However, except for possible
complications introduced by new style class or anything I have
forgotten about, the type of an object is fixed at creation (along
with its id).  There is no context dependence at all.

Terry J. Reedy





More information about the Python-list mailing list