Subject: Equivalent of perl's Pod::Usage?
From: Neil Cerutti
Date: 12/8/2007 2:05:10 PM
On 2007-12-08, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
> On Fri, 7 Dec 2007 20:12:21 +0000, Adam Funk <a24061@ducksburg.com>
> declaimed the following in comp.lang.python:
>
>> I'm using to using Pod::Usage in my Perl programs (a snipped example
>> is shown below, if you're interested) to generate a little man page
>> when they are called with the -h option.
>>
>> Is there an equivalent in Python?
>>
> I'd suggest you look in the Python references for docstring and/or
> __doc__
I found the example incomprehensible, so I looked it up in
perldoc. Anyhow, Python doesn't have it. Combining printing
various verboseness of usage messages with setting exit codes
with calling the exit function seems a little bizarre.
But I believe optparse will handle parsing arguments and printing
usage messages, though not, I think, setting verbosity levels and
exiting the program.
--
Neil Cerutti
Subject: Equivalent of perl's Pod::Usage?
From: Adam Funk
Date: 12/10/2007 11:48:57 AM
On 2007-12-08, Dennis Lee Bieber wrote:
> On Fri, 7 Dec 2007 20:12:21 +0000, Adam Funk <a24061@ducksburg.com>
> declaimed the following in comp.lang.python:
>
>> I'm using to using Pod::Usage in my Perl programs (a snipped example
>> is shown below, if you're interested) to generate a little man page
>> when they are called with the -h option.
>>
>> Is there an equivalent in Python?
>>
> I'd suggest you look in the Python references for docstring and/or
> __doc__
Thanks.
Subject: Equivalent of perl's Pod::Usage?
From: Adam Funk
Date: 12/13/2007 9:57:28 PM
On 2007-12-10, Nick Craig-Wood wrote:
> That said, python does a good job of turning doc strings and class
> descriptions into man pages even without any special markup, if you
> wrote docstrings everywhere. Try pydoc on any bit of python (without
> the .py) and you'll see what I mean
>
> As for Pod::Usage - write the instructions for your script as a
> docstring at the top of your file, then use this little function...
>
> def usage(error):
> """
> Print the usage, an error message, then exit with an error
> """
> print >>sys.stderr, globals()['__doc__']
> print >>sys.stderr, error
> sys.exit(1)
That looks useful; thanks.
|