Resolving declaring class of a method at runtime

Janne Härkönen janne.t.harkonen at gmail.com
Fri Nov 16 12:02:25 EST 2007


On Nov 15, 2007 11:07 PM, Steven D'Aprano
<steve at remove-this-cybersource.com.au> wrote:
> On Thu, 15 Nov 2007 13:01:27 +0200, Janne Härkönen
> wrote:
>
> Have you tried looking at dir(TheClass) to see what it lists?

This is the first thing I did, but it shows both the inherited and own
methods.

> Also helpful is TheClass.__dict__.keys().

This actually does the trick, thanks for the tip!

> Python has powerful introspection abilities. Learn to use them, and you
> too will be able to impress your friends with your Python knowledge.

I actually use introspection very frequently, but almost always through dir().


> X is an "old style" class. Most people probably shouldn't use old style
> classes, for various reasons. To use new style classes, you inherit from
> object:

I am also aware of old and new style classes, this was the fastest way to
type it in console :)

-- 
__janne



More information about the Python-list mailing list