guide to introspecting python?

M

Mark Harrison

What's a good document to read in order to understand some
of python's introspective functions?

I'm trying to recurse through a module and print information
about its contents. dir() does something similar to what
I have in mind, but it's documented to be more for human
interaction than definitive programmatic correctness,
so I'd like to call or look at whatever it's using.

This bit of code never finishes because dir(something)
and dir(something.__call__) return the same thing.

def rdir(item, v=""):
print "%s%s"%(v,item)
for i in dir(item):
rdir(i, v+" ")

import os
rdir(os)


Any help/pointers appreciated!

Thanks,
Mark

PS, you will probably recognize this as my attempt to
generate programatically the module/function/parameter
index I previously asked about...
 
P

Peter Hansen

Mark said:
What's a good document to read in order to understand some
of python's introspective functions? ....
PS, you will probably recognize this as my attempt to
generate programatically the module/function/parameter
index I previously asked about...

Isn't the "inspect" standard module exactly what you need?
 
S

Skip Montanaro

Mark> def rdir(item, v=""):
Mark> print "%s%s"%(v,item)
Mark> for i in dir(item):
Mark> rdir(i, v+" ")

Mark> import os
Mark> rdir(os)

Problem is, dir() is already recursive:
... def a(self): pass
... ... def b(self): pass
...
>>> class C(A,B): pass ...
>>> c = C()
>>> dir(c) ['__doc__', '__module__', 'a', 'b']
>>> dir(C)
['__doc__', '__module__', 'a', 'b']

As others have suggested, the inspect module is probably a good place to
start.

Skip
 
C

Chris Irish

I saw that you work for pixar. Do they use python alot? Is it mostly
for making tools for the artists or something else? And one last
question does pixar use their own software for rendering or more
commercial stuff like Maya/3d Studio Max. Sorry for being nosey.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top