Getting a class name from within main
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Wed Feb 7 05:02:21 EST 2007
In <1170838959.441543.19720 at s48g2000cws.googlegroups.com>, bg_ie wrote:
> class MyClass:
> def __init__(self):
> print (__name__.split("."))[-1]
>
> if __name__ == '__main__':
> MyClassName = "MyClass"
>
> I can print the name of the class from within the class scope as seen
> above in the init, but is there any way of printing it from within the
> main without creating an object of the MyClass type. I need to assign
> the name of the class within my script, to a variable in main.
Yes::
print MyClass.__name__
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list