language lawyering - doc strings
Tim Peters
tim.one at home.com
Wed Aug 29 21:02:16 EDT 2001
[gcash]
> I know this is being pedantic, but where's the syntactical spec for
> documentation strings in the language reference?
I don't think there is one! They're ordinary string literals, of course,
and must be the first non-blank non-comment statement at the top of a
module, or following a class or def stmt.
> I was looking at the 2.1.1 docs and I'd expect it to be in "4.1 Code
> blocks, execution frames, and namespaces"
I sure wouldn't expect it there. Maybe that's the problem -- nobody can
figure out where to put it <wink>.
> but the only reference to documentation strings is where it mentions
> the __doc__ attribute.
>
> I noticed this when someone asserted you can't have doc strings for
> classes.
In that case, they can't -- but you can.
>>> class C:
... pass
...
>>> dir(C)
['__doc__', '__module__']
>>> print C.__doc__
None
>>> class C:
... "pass"
...
>>> print C.__doc__
pass
>>>
More information about the Python-list
mailing list