python2.2: type('name') -> <type 'str'> ??

Francisco frandebo at
Wed Jul 25 12:24:20 EDT 2001

On Wed, 25 Jul 2001, Tim Peters wrote:

> > >>> type('')
> > <type 'str'>
> >
> >  while I expected to get <type 'string'>.

> No, that's the way it works (today).  Under the type/class unification
> scheme, type names also work as constructors.  Since str() was always the
> way to build a string in Python, that's a natural name for its type.
> Note this cute consequence:
> >>> x = 1L
> >>> type(x)(3)
> 3L
> >>>
> That is, type() in 2.2a1 truly returns a constructor, and type(1L)(y) is the
> same as long(y).  Likewise for
> >>> type("abc")(42)
> '42'
> >>> type("abc") is str
> 1
> >>> type(1L) is long
> 1

 Thank you for the examples, it helped me to understand what the change
 was for.

> I'm not sure the type names will stay this way, but determining that is part
> of what an alpha release is for.  On a scale of 1 to 12, were you merely
> surprised by the change or truly upset <wink>?

 Hum, if type() is going to work as a contructor I think it's better to
 have the type('') as <type 'str'>. But yes, I was surprised since I
 didn't knew this change was going to happen and just a little upset
 because there is no explicit mention to changing type _names_ in
 the "Release Notes" at SourceForge (the very first place I went). 

 thank you (and to Guido) for the help,

 best regards,
  São Paulo, Brasil.

More information about the Python-list mailing list