Optparse and help formatting?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Sep 30 09:19:06 EDT 2007
On Sun, 30 Sep 2007 07:37:10 -0500, Tim Chase wrote:
> def format_option(self, option):
> # The help for each option consists of two parts:
> # * the opt strings and metavars
[snip]
Tim, I notice you're using lots of # lines as comments to describe the
function. Perhaps you should consider using docstrings instead.
Pardon me if I'm telling you what you already know...
A docstring is a string that immediately follows a class, function or
method declaration, or at the beginning of a module:
def parrot():
"This is a doc string."
s = "this is not a docstring"
The advantage of docstrings is that unlike # comments, they aren't
discarded at compile time, and can be accessed by the caller:
>>> parrot.__doc__
'This is a doc string'
This is especially useful in the interactive interpreter, where
help(object) will grab the docstring and format it nicely on screen.
--
Steven.
More information about the Python-list
mailing list