[Tutor] Best way to convert a type into string

Magnus Lycka magnus@thinkware.se
Thu Jan 9 21:25:59 2003


At 15:08 2003-01-09 -0700, Bob Gailer wrote:
>repr(type(1))[7:-2] does it; I was hoping for something simpler.

str(type(1))[7:-2] is one character shorter. Really Bob,
17 characters in excess to the variable name. Isn't that
simple?

def _(x): return str(type(x))[7:-2]

_(1)
'int'

_('Hello')
'string'

Short enough?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se