How to tell which subclass was used to instantiate object

John Roth newsgroups at jhrothjr.com
Sat May 1 09:10:12 EDT 2004


"Frank Millman" <frank at chagford.com> wrote in message
news:246a4e07.0405010447.11ed5400 at posting.google.com...
> Hi all
>
> I have a question regarding inheritance. I have come up with a
> solution, but it is not very elegant - I am sure there is a more
> pythonic approach. Assume the following class definitions.
>
[...]
>
> Is there a more direct way for a top-level class to determine which
> subclasses were used to instantiate it?

Look at the __class__ attribute. Specifically, __class__.__name__
should tell you the name of the class.

John Roth
>
> Thanks
>
> Frank Millman





More information about the Python-list mailing list