should I put old or new style classes in my book?

2008-05-29 Thread allendowney
Hi All, I am working on a revised edition of How To Think Like a Computer Scientist, which is going to be called Think Python. It will be published by Cambridge University Press, but there will still be a free version under the GNU FDL. You can see the latest version at thinkpython.com; I am rev

Can I find out (dynamically) where a method is defined?

2008-06-09 Thread allendowney
Hi All. In a complex inheritance hierarchy, it is sometimes difficult to find where a method is defined. I thought it might be possible to get this info from the method object itself, but it looks like maybe not. Here is the test case I tried: class A(object): def method(): pass cl

Re: Can I find out (dynamically) where a method is defined?

2008-06-09 Thread allendowney
Thanks Maric! That's very close to what I want, although using dir() can be misleading because if you invoke it on class B you get all of class A's methods as well. I took your idea and wrote it up like this: def find_defining_class(obj, meth_name): """find and return the class object that w