[Tutor] Best way to convert a type into string
Michael Janssen
Janssen@rz.uni-frankfurt.de
Fri Jan 10 12:49:01 2003
On Fri, 10 Jan 2003, Bob Gailer wrote:
> At 12:38 PM 1/10/2003 +0000, Gon=E7alo Rodrigues wrote:
>
> > > >>> type(1)
> > > <type 'int'>
> > >
> > > What's the best way to get the string "int" from this?
> >
> >Here is the simplest:
> >
> > >>> print type(1).__name__
> >int
>
> That's what I was looking for. Something already in the language. How doe=
s
> one discover things like this?
One way to discover something, which you don't find in the docs ist to use
the rlcompleter-module:
18:37 ./janssenm> cat .pythonrc
### enables tab-completion
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")
now you can type at interactive prompt:
typeobject =3D type(1)
typeobject.[tab][tab]
and you will get the complete list of every method and variable from
typeobjects. From this point you have to gess and try.
Michael
> Are they in the documentation? dir(type(1))
> reveals a lot of keys, but __name__ is not amongst them.
>
> Bob Gailer
> mailto:ramrom@earthling.net
> 303 442 2625
>