How would you change a class type name to something other than classobj?
class bob():
pass
foo = bob
print "%s" % type(foo).__name__
which gets me ‘classobj’.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In your example, you’ve defined
fooas a reference to the class definition ofbob, not to an instance of bob. The type of an (old-style) class is indeedclassobj.If you instantiate
bob, on the other hand, the result will be different:If you just want to see the name of the
bobtype without instantiating it, use:This works because
bobis already a class type, and therefore has a__name__property that you can query.