How to get the 'name' of an int

Michele Simionato mis6 at pitt.edu
Fri Feb 28 09:16:17 EST 2003


Just <just at xs4all.nl> wrote in message news:<just-779694.10462828022003 at news1.news.xs4all.nl>...
> You need to "reset your brain":
>   http://effbot.org/guides/python-objects.htm
> 
> HTH,
> 
> Just


>From the Effbot guide:

          Objects

          All Python objects have this:

               a unique identity (an integer, returned by id(x))
               a type (returned by type(x))
               some content

          You cannot change the identity.

          You cannot change the type.
              ^^^^^^

However:

>>> class A(object): pass
...
>>> class B(object): pass
...
>>> a=A()
>>> a.__class__=B
>>> type(a)
<class '__main__.B'>

Therefore I would say you "should" not change the type, but you can.


                                                    Michele




More information about the Python-list mailing list