Interactively, you can display it with:
help(my_func)
Or from code you can retrieve it with (surround it with print(.) to get a formatted output):
my_func.__doc__
Answer from unwind on Stack OverflowAdvice on writing some docstrings
python - Getting the docstring from a function - Stack Overflow
Propper way to write DocStrings
Do short functions need docstrings?
Videos
I need to write docstrings for every method and property in this file:
https://github.com/golemfactory/yapapi/blob/master/yapapi/services/service_runner.py
A couple questions.
Should you write a docstring for an init method? I suppose it depends? This one seems self explanatory. Should I just state what the code does? “ServiceRunner class is initialized with four parameters: job, instance, instance_tasks, and stopped.”
I could explain what each of those do. I actually have some questions about them. “Job” is clearly passed the string “job”, so I don’t understand the later call “job.id” - the string returns an ID?
As for: self._instances: List[Service] = [] - how can you pass an entire statement as an attribute? They convert “Service” to a list but then assign it as an empty list… will the result be the list of services or the empty list?
Just that for now. Please let me know if you understand this a bit better than I do.
Thanks very much
Interactively, you can display it with:
help(my_func)
Or from code you can retrieve it with (surround it with print(.) to get a formatted output):
my_func.__doc__
You can also use inspect.getdoc. It cleans up the __doc__ by normalizing tabs to spaces and left shifting the doc body to remove common leading spaces.