how to print class names, not references
Bengt Richter
bokr at oz.net
Sun Mar 17 22:47:22 EST 2002
On Mon, 18 Mar 2002 01:36:53 +0000, "a.clarke11" <a.clarke11 at pop.ntlworld.com> wrote:
>Hi,
>I wrote a function of x, where later in the program x is substituted by
>class names. In the function, print x is used, but this returns
><__main__.Player instance at 0x38b1ce90> rather than the plain old class
>name that I wanted.
>How can I print the name instead?
>Thanks for your help, Pythoneers...
>
>>> class CwithClassName:
... pass
...
>>> c = CwithClassName()
>>> c
<__main__.CwithClassName instance at 0x0084AF40>
>>> Calias = CwithClassName
>>> calias = c
>>> Calias
<class __main__.CwithClassName at 0x0084B0B0>
>>> calias
<__main__.CwithClassName instance at 0x0084AF40>
>>> Calias.__name__
'CwithClassName'
>>> calias.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: CwithClassName instance has no attribute '__name__'
>>> calias.__class__.__name__
'CwithClassName'
Does any of that help?
Regards,
Bengt Richter
More information about the Python-list
mailing list