diff options
author | steven.bethard <devnull@localhost> | 2009-07-13 01:06:01 +0000 |
---|---|---|
committer | steven.bethard <devnull@localhost> | 2009-07-13 01:06:01 +0000 |
commit | dfb0e513927c55c44eb4dc76490b0748dfe078d7 (patch) | |
tree | 3f670b05f39c1d805ff8cee182bdc57e47c05d55 /doc | |
parent | 849841ad0021e632141f9c7353bd98264b193fe2 (diff) | |
download | argparse-dfb0e513927c55c44eb4dc76490b0748dfe078d7.tar.gz |
Document parse_known_args.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/source/other-methods.rst | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/source/other-methods.rst b/doc/source/other-methods.rst index 1003aa3..5934554 100644 --- a/doc/source/other-methods.rst +++ b/doc/source/other-methods.rst @@ -1,6 +1,24 @@ Other methods
=============
+Partial parsing
+---------------
+
+.. method:: parse_known_args([args], [namespace])
+
+Sometimes a script may only parse a few of the command line arguments, passing the remaining arguments on to another script or program.
+In these cases, the :meth:`parse_known_args` method can be useful.
+It works much like :meth:`parse_args` except that it does not produce an error when extra arguments are present.
+Instead, it returns a two item tuple containing the populated namespace and the list of remaining argument strings.
+::
+
+ >>> parser = argparse.ArgumentParser()
+ >>> parser.add_argument('--foo', action='store_true')
+ >>> parser.add_argument('bar')
+ >>> parser.parse_known_args(['--foo', '--badger', 'BAR', 'spam'])
+ (Namespace(bar='BAR', foo=True), ['--badger', 'spam'])
+
+
Printing help
-------------
|