Convert type() to string?

Donn Cave donn at u.washington.edu
Tue Nov 12 19:04:43 EST 2002


Quoth "Robert Oschler" <Oschler at earthlink.net>:
| 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).

Arguably the best way might be "don't do that!"  and do
  print padstr, type(x)      instead.

But anyway, the "print" command in effect uses the str() function to make
type(x) into a string, and so can you.  The alternative would be repr(),
which is an interesting philosophical dilemma but not an interesting
practical one, since they come out the same in this case.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list