[Python-checkins] r81491 - in python/branches/py3k: Doc/library/argparse.rst Doc/library/getopt.rst Doc/library/optparse.rst

steven.bethard python-checkins at python.org
Mon May 24 05:21:08 CEST 2010


Author: steven.bethard
Date: Mon May 24 05:21:08 2010
New Revision: 81491

Log:
Merged revisions 81490 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81490 | steven.bethard | 2010-05-23 19:38:00 -0700 (Sun, 23 May 2010) | 1 line
  
  argparse documentation updates (including updates to optparse and getopt documentation that were promised in the PEP)
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Doc/library/argparse.rst
   python/branches/py3k/Doc/library/getopt.rst
   python/branches/py3k/Doc/library/optparse.rst

Modified: python/branches/py3k/Doc/library/argparse.rst
==============================================================================
--- python/branches/py3k/Doc/library/argparse.rst	(original)
+++ python/branches/py3k/Doc/library/argparse.rst	Mon May 24 05:21:08 2010
@@ -672,8 +672,8 @@
 
     >>> import argparse
     >>> parser = argparse.ArgumentParser(prog='PROG')
-    >>> parser.add_argument('-v', '--version', action='version', version='%(prog)s 2.0')
-    >>> parser.parse_args(['-v'])
+    >>> parser.add_argument('--version', action='version', version='%(prog)s 2.0')
+    >>> parser.parse_args(['--version'])
     PROG 2.0
 
 You can also specify an arbitrary action by passing an object that implements
@@ -1725,3 +1725,6 @@
 * Replace strings with implicit arguments such as ``%default`` or ``%prog`` with
   the standard python syntax to use dictionaries to format strings, that is,
   ``%(default)s`` and ``%(prog)s``.
+
+* Replace the OptionParser constructor ``version`` argument with a call to
+  ``parser.add_argument('--version', action='version', version='<the version>')``

Modified: python/branches/py3k/Doc/library/getopt.rst
==============================================================================
--- python/branches/py3k/Doc/library/getopt.rst	(original)
+++ python/branches/py3k/Doc/library/getopt.rst	Mon May 24 05:21:08 2010
@@ -5,6 +5,12 @@
    :synopsis: Portable parser for command line options; support both short and
               long option names.
 
+.. note::
+   The :mod:`getopt` module is a parser for command line options whose API is
+   designed to be familiar to users of the C :cfunc:`getopt` function. Users who
+   are unfamiliar with the C :cfunc:`getopt` function or who would like to write
+   less code and get better help and error messages should consider using the
+   :mod:`argparse` module instead.
 
 This module helps scripts to parse the command line arguments in ``sys.argv``.
 It supports the same conventions as the Unix :cfunc:`getopt` function (including
@@ -136,9 +142,21 @@
    if __name__ == "__main__":
        main()
 
+Note that an equivalent command line interface could be produced with less code
+and more informative help and error messages by using the :mod:`argparse` module::
+
+   import argparse
+
+   if __name__ == '__main__':
+       parser = argparse.ArgumentParser()
+       parser.add_argument('-o', '--output')
+       parser.add_argument('-v', dest='verbose', action='store_true')
+       args = parser.parse_args()
+       # ... do something with args.output ...
+       # ... do something with args.verbose ..
 
 .. seealso::
 
-   Module :mod:`optparse`
-      More object-oriented command line option parsing.
+   Module :mod:`argparse`
+      Alternative command line option and argument parsing library.
 

Modified: python/branches/py3k/Doc/library/optparse.rst
==============================================================================
--- python/branches/py3k/Doc/library/optparse.rst	(original)
+++ python/branches/py3k/Doc/library/optparse.rst	Mon May 24 05:21:08 2010
@@ -3,6 +3,12 @@
 
 .. module:: optparse
    :synopsis: Command-line option parsing library.
+   :deprecated:
+
+.. deprecated:: 2.7
+   The :mod:`optparse` module is deprecated and will not be developed further;
+   development will continue with the :mod:`argparse` module.
+
 .. moduleauthor:: Greg Ward <gward at python.net>
 .. sectionauthor:: Greg Ward <gward at python.net>
 


More information about the Python-checkins mailing list