class declaration shortcut

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at
Thu Mar 1 10:44:48 CET 2007

Michele Simionato wrote:
> On Mar 1, 9:40 am, Marc 'BlackJack' Rintsch <bj_... at>
>> In <54msaoF21c6h... at>, Bjoern Schliessmann

>>> But what's it (__name__) good for?
>> As objects don't know to which name they are bound, that's a good
>> way to give some information in stack traces or when doing
>> introspection.
> Also, the name is used by pickle to find the class of pickled
> instances.

Mh. I suspect there's also more to it than I see now, but this
__name__ seems quite useless to me. What if I rebind the class'
name after definition? Or is it really just for some manual
introspection? If it is, it seems a bit of an overkill to me.

>>> class Spam(object):
...     pass
>>> Ham = Spam
>>> Spam = 0
>>> test = Ham()
>>> test.__class__
<class '__main__.Spam'>
>>> test.__class__.__name__
>>> Spam



BOFH excuse #137:

User was distributing pornography on server; system seized by FBI.

More information about the Python-list mailing list