Dynamic function docstring
Posted
by Tom Aldcroft
on Stack Overflow
See other posts from Stack Overflow
or by Tom Aldcroft
Published on 2010-04-22T19:36:10Z
Indexed on
2010/04/22
19:53 UTC
Read the original article
Hit count: 427
python
I'd like to write a python function that has a dynamically created docstring. In essence for a function func()
I want func.__doc__
to be a descriptor that calls a custom __get__
function create the docstring on request. Then help(func)
should return the dynamically generated docstring.
The context here is to write a python package wrapping a large number of command line tools in an existing analysis package. Each tool becomes a similarly named module function (created via function factory and inserted into the module namespace), with the function documentation and interface arguments dynamically generated via the analysis package.
© Stack Overflow or respective owner