Convert type() to string?
Alex Martelli
aleax at aleax.it
Wed Nov 13 07:37:24 EST 2002
Robert Oschler wrote:
> I want to be able to print out the type() of a string for a "structure
> walker" I'm writing. I need to be able to prepend a string of pad
> characters to the type() so the following:
>
> print padstr + type(x)
>
> won't work because type() does not return a string. What's a good way to
> do
> this? I'm using Python 2.1 + Python 2.2 (2.1 for Jython).
Either
print "%s%s" % (padstr, type(x))
or
print padstr + str(type(x))
(or many other variations) will work for your purposes.
Alex
More information about the Python-list
mailing list