Hi all,

I am testing a somewhat large module, and I would like to automate the testing of the documentation (I know, I could just look at the code, but I wanted to make sure *and* the question became a cool one :cheesy:)

Here's the basic idea:

for i in dir(MyClass):
    if not i.startswith("__"):

which code fails because i is not a member function of MyClass! :p What's the right way to do this?

Jeff Cagle

Got it. Hooray for Google:

for i in dir(MyClass):
    if not i.startswith("__"):

Thanks for sharing this insight!

eval(str) Evaluate a string and return an object

slight improvement:

for i in dir(MyClass):
    if not i.startswith("__") and callable(eval("MyClass."+i)):

I found that the former would occasionally dump me into the interactive help! :lol:

Another variation:

# using __doc__
for method in dir(MyClass):
    obj = eval("MyClass."+method)
    if not method.startswith("__") and callable(obj):
        print "method %s:" % method
        print obj.__doc__