Re: Optparse and help formatting?



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.
.



Relevant Pages

  • Re: Thoughts on using isinstance
    ... its parameters is best placed in the docstring. ... So in practice you end up writing "a string", and leave the rest of the ... level that I think doing explicit parameter validation can be helpful. ... When I started using Python some 7 years ago, I strongly believed in strong static typing, and spent monthes fighting against the language. ...
    (comp.lang.python)
  • Re: Thoughts on using isinstance
    ... its parameters is best placed in the docstring. ... This is another place where the "don't validate, ... So in practice you end up writing "a string", and leave the rest of the ... level that I think doing explicit parameter validation can be helpful. ...
    (comp.lang.python)
  • Re: whitespace , comment stripper, and EOL converter
    ... at how to determine a docstring from a regular tripleqoted string;) ... Jean Brouwers ... """Python source stripper ...
    (comp.lang.python)
  • Accessing docstrings at runtime?
    ... How do I print the docstring for a class property? ... When I run the code below, I get the docstring for the string module ... def setx: ...
    (comp.lang.python)
  • Re: Reflection SRFI
    ... this would be an string that goes right ... be retrieved by using a function named docstring with the ... "subtracts the first argument from the second ...
    (comp.lang.scheme)