Using instance as __doc__
unendliche at hanmail.net
Thu Jun 5 04:04:21 CEST 2003
On Python 2.2.2 on Win XP, I tried the following:
return "This is a documentation."
my_function.__doc__ = MyDoc()
I hope my intent here is clear.
I expected to see the online help, but failed. After digging the source,
I found that help() uses inspect.getdoc() to get docstrings.
# inspect.py around line 270
doc = object.__doc__
if not isinstance(doc, (str, unicode)):
So... Python throws out __doc__ if it is not a real string. Why not use
something like "doc = str(doc)" instead? Yeah, quite useless, perhaps.
I have no idea of possible use cases. But if there is some hidden reason
for not to use str() on instance __doc__, please enlighten me.
-- Seo Sanghyeon
More information about the Python-list