Fix Python – Getting the docstring from a function

Question

Asked By – Teifion

I have the following function:

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

How do I get access to the docstring?

Now we will see solution for issue: Getting the docstring from a function


Answer

Interactively, you can display it with

help(my_func)

Or from code you can retrieve it with

my_func.__doc__

This question is answered By – unwind

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0