0

I would like to extract only commented data from python program.

def addlist():
    '''
    method to add all the number in a list
    :return:integer
    '''
    input_number = [1, 2, 3, 4, 5]
    sum = reduce(lambda x, y: x + y, input_number, 10)
    print("sum is:", sum)
    return sum

I was trying some regex but could not do it successfully. I want to get

'method to add all the number in a list:return:integer'

Any help is appreciated

2
  • you can get it using __doc__ method, or you can use a tool such as pydoc that will extract those strings as documentation, and then you can template the documentation for whatever you want to present it. Commented Apr 22, 2019 at 10:22
  • @Dan remove regex tag from the question as this question has been answered and it has nothing to do with regex. tx. Commented Apr 22, 2019 at 14:35

1 Answer 1

2

You can retrieve it with addList.__doc__.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.