3

I want to extract a docstring from every function in a python module. Thought, help does the intended action, It would print out a lot of extra stuff which I do not need. I have tried .__ doc__ as well. However, Even that does print out a lot of stuff and also print \n and \t.

eg.

def Foo():
"""
This is
a multiline
comment
"""
    pass:

I want something which will give me only the comment as a single line or in the specified format as is.

>>> print (some operation on foo)
>>> "This is a multiline comment"
>>>

How do I remove of all the extra stuff.

Greater picture: I have a module with a search function to find all functions and I want to display their descriptions along with functions

>>> find('*', maths) # suppose maths is a module
>>> shapes.square "This is square"
    shapes.cube   "This is cube"

P.S I already have the find function I just need the string to append in the print statement.

Thnaks

7
  • Try this anwser: stackoverflow.com/questions/713138/… Commented Dec 13, 2017 at 21:57
  • @Abe I have already tried that, however it does print out a lot of excess info which I do not want. Commented Dec 13, 2017 at 22:00
  • 1
    Well, you can just "\n".join the lines, but what if the docstring contains information on parameters, or even test cases? Commented Dec 13, 2017 at 22:03
  • I want to join those line. but how do I get those first. That is the question I asked? Commented Dec 13, 2017 at 22:10
  • 1
    Ummm, Foo.__doc__.replace("\n", " ")? Commented Dec 13, 2017 at 22:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.