FAQ
Thanks for confirming my astonishment. I was sure they should be there too.
Maybe I'm making some egregious error in my code. This executes in my
sys.settrace() function, on a "call"-type call to that function. The module
must be fully initialized because I'm calling a user method in a class in
that module.

functions =
inspect.getmembers(module,inspect.isfunction)
print "functions: %s"%functions
classes = inspect.getmembers(module,inspect.isclass)
if classes==[]:
moduleDict = module.__dict__
for mkey in moduleDict.keys():
if inspect.isclass(moduleDict[mkey]):
classes.append((mkey,moduleDict[mkey]))
print "classes: %s"%classes

always prints:
functions: [....] #lists functions properly
classes: [] #always empty

I thought that perhaps the inspect.isclass function didn't do what I thought
it should, so I tried just printing the moduleDict (in place of the "for
mkey.." loop above) and, sure enough, the class names are not in there. :-O

I'm willing to accept that I've made a stupid mistake, but I sure can't find
it. Any suggestions?


Greg Ewing wrote:
Robert Dickinson wrote:
I inspected the __dict__ of the
module; the classes are not there, either

That's strange, they certainly should be there (every name
accessible through module.name should be there, in fact).

Have you somehow got hold of an incompletely-constructed
module? That can happen if importation of a module fails
part way through.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 5 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedAug 19, '02 at 11:01p
activeAug 20, '02 at 5:29p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase