How to create a docstring for a module?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Dec 6 08:43:40 EST 2009


On Sun, 06 Dec 2009 06:34:17 -0600, Tim Chase wrote:

>> * He hasn't actually defined a docstring. Docstrings have to be string
>> literals, you can't do this:
>> 
>> """%s does everything you could possibly want.""" % "xyz"
> 
> I've occasionally wanted something like this, and have found that it can
> be done by manually assigning to __doc__ (either at the module-level or
> classes) which can make some documentation bits a little easier:

Unfortunately, and surprisingly, assigning to __doc__ doesn't work with 
new-style classes.

>>> class K(object):
...     pass
...
>>> K.__doc__ is None
True
>>> K.__doc__ = "docstring"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: attribute '__doc__' of 'type' objects is not writable




-- 
Steven



More information about the Python-list mailing list