searching for __doc__ from the interactive cmd line

Sean Montgomery sean at
Wed May 16 18:52:15 CEST 2001

Greetings from a tyro Python enthusiast.

I like it that you can get some documentation at the interactive command
line by printing __doc__ strings, so I thought I'd automate things a bit.
Being a lazy & stupid beginner I don't always know which module contains the
method I'm interested in, so I thought it would be cool to do something

def getMethodDocString(methodName):
    method = findMethodInList(globals().values(), methodName)
    if method != None and hasattr(method, "__doc__"):
        print method, method.__doc__
        print "Sorry, no __doc__"

Or something like that - I hope you get the idea.  Then I could type:


That's when the trouble starts.  I don't know if it's actually
myModule.myThingy or myOtherModule.myThingy or maybe there isn't even a
myThingy at all... that's the whole reason I'm writing this. And neither
does the interpreter: if myThingy isn't in scope right now, I get an
exception before my function ever gets called.

So I try:


And off I go.  But is there a way to set a global exception handler of some
sort when I'm running at the interactive command line so that I don't have
to quote myThingy? I told ya I was lazy ;-)

Thanks for any info.  I'm assuming someone's already done something like
this before:

myThingy is:
with __doc__:
    myThingy(spam, eggs) -> string
    Concatenates the arguments, what should be strings, sends them to the
    synthesizer, then returns a rude message in a string

Any pointers to source?

Thanks again!

More information about the Python-list mailing list