type vs. class

Greg Jorgensen gregj at pobox.com
Tue Dec 12 08:37:07 CET 2000


"Alex Martelli" <aleaxit at yahoo.com> wrote:

> However, to satisfy Thomas's request as he posed it...: when x is an
> instance of some class, you can learn WHICH class it's an instance
> of, through x's __class__ attribute (you can get the NAME of the
> class as a string, through the class-object's own __name__ attribute):
>
> >>> class X:
> ...   pass
> ...
> >>> x=X()
> >>> x.__class__
> <class __main__.X at 007F76CC>
> >>> x.__class__.__name__
> 'X'
> >>>

Thanks... I didn't know about the __class__ attribute. I've never had a
reason to use it.

--
Greg Jorgensen
Deschooling Society
Portland, Oregon, USA
gregj at pobox.com





More information about the Python-list mailing list