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("__"):
        help(MyClass.i)

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

Thanks,
Jeff Cagle

Recommended Answers

All 4 Replies

Got it. Hooray for Google:

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

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)):
        help(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__
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.