I would like to do this:
FOO_CONSTANT = 1
def foo():
"""asdf """ + str(FOO_CONSTANT)
print(foo.__doc__)
Which should print:
asdf 1
But instead it prints
None
I can get the expected output with
FOO_CONSTANT = 1
def foo():
"""asdf """
foo.__doc__ += str(FOO_CONSTANT)
print(foo.__doc__)
but spreading the docstring across the code feels terrible.
Is it possible to include the value of a constant in a doc-string?
PS: I found this which is remotely related. The attempted approach there also does not produce a valid doc string, and note that it is about generating a dynamic docstring, while my FOO_CONSTANT
is not expected to change. I just want to avoid repeating myself. The name FOO_CONSTANT
has no meaning to the reader of the docstring, but the value does, and it appears in several docstrings where I do not want to repeat it.