In Python, it is possible to extract the docstring of a function:
class MyClass:
def my_method(self):
"""This is the help message,
on multiple lines.
"""
pass
print(MyClass.my_method.__doc__)
The result is:
This is the help message,
on multiple lines.
What is annoying is that it results in many meaningless spaces: the whitespaces exist to keep the code clean, but are not meant to be part of the message.
Is there a way to get rid of them? Note that I would like to remove only the meaningless ones. So, calls to lstrip
or equivalent won't work.
If there are meaningful spaces, I would like to keep them:
class MyClass2:
def my_method(self):
"""This is the help message,
on multiple lines.
This one is intentionally more indented.
"""
pass
print(MyClass2.my_method.__doc__)
Desired result:
This is the help message,
on multiple lines.
This one is intentionally more indented.