Thursday, April 28, 2011

Getting the docstring from a function

I have the following function:

def my_func():
    """My docstring is both funny and informative"""
    pass

How do I get access to the docstring?

From stackoverflow
  • Interactively, you can display it with

    help(my_func)
    

    Or from code you can retrieve it with

    my_func.__doc__
    
    Daren Thomas : BTW: This technique works with builtin functions as well as modules and classes (test help() with objects too - might also work). This makes your python shell an interactive help shell!

0 comments:

Post a Comment