[Python-checkins] cpython (merge 3.5 -> default): Issue #20598: Merge argparse docs from 3.5

martin.panter python-checkins at python.org
Tue Apr 26 07:48:49 EDT 2016


https://hg.python.org/cpython/rev/14cb17682831
changeset: 101158:14cb17682831
parent: 101155:090502a0c69c
parent: 101157:49561532504c
user: Martin Panter <vadmium+py at gmail.com>
date: Tue Apr 26 11:47:10 2016 +0000
summary:
 Issue #20598: Merge argparse docs from 3.5
files:
 Doc/library/argparse.rst | 46 ++++++++++++++--------------
 1 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -725,7 +725,7 @@
 
 >>> parser = argparse.ArgumentParser()
 >>> parser.add_argument('--foo', action='store_const', const=42)
- >>> parser.parse_args('--foo'.split())
+ >>> parser.parse_args(['--foo'])
 Namespace(foo=42)
 
 * ``'store_true'`` and ``'store_false'`` - These are special cases of
@@ -766,7 +766,7 @@
 
 >>> parser = argparse.ArgumentParser()
 >>> parser.add_argument('--verbose', '-v', action='count')
- >>> parser.parse_args('-vvv'.split())
+ >>> parser.parse_args(['-vvv'])
 Namespace(verbose=3)
 
 * ``'help'`` - This prints a complete help message for all the options in the
@@ -841,11 +841,11 @@
 >>> parser = argparse.ArgumentParser()
 >>> parser.add_argument('--foo', nargs='?', const='c', default='d')
 >>> parser.add_argument('bar', nargs='?', default='d')
- >>> parser.parse_args('XX --foo YY'.split())
+ >>> parser.parse_args(['XX', '--foo', 'YY'])
 Namespace(bar='XX', foo='YY')
- >>> parser.parse_args('XX --foo'.split())
+ >>> parser.parse_args(['XX', '--foo'])
 Namespace(bar='XX', foo='c')
- >>> parser.parse_args(''.split())
+ >>> parser.parse_args([])
 Namespace(bar='d', foo='d')
 
 One of the more common uses of ``nargs='?'`` is to allow optional input and
@@ -881,9 +881,9 @@
 
 >>> parser = argparse.ArgumentParser(prog='PROG')
 >>> parser.add_argument('foo', nargs='+')
- >>> parser.parse_args('a b'.split())
+ >>> parser.parse_args(['a', 'b'])
 Namespace(foo=['a', 'b'])
- >>> parser.parse_args(''.split())
+ >>> parser.parse_args([])
 usage: PROG [-h] foo [foo ...]
 PROG: error: too few arguments
 
@@ -938,9 +938,9 @@
 
 >>> parser = argparse.ArgumentParser()
 >>> parser.add_argument('--foo', default=42)
- >>> parser.parse_args('--foo 2'.split())
+ >>> parser.parse_args(['--foo', '2'])
 Namespace(foo='2')
- >>> parser.parse_args(''.split())
+ >>> parser.parse_args([])
 Namespace(foo=42)
 
 If the ``default`` value is a string, the parser parses the value as if it
@@ -959,9 +959,9 @@
 
 >>> parser = argparse.ArgumentParser()
 >>> parser.add_argument('foo', nargs='?', default=42)
- >>> parser.parse_args('a'.split())
+ >>> parser.parse_args(['a'])
 Namespace(foo='a')
- >>> parser.parse_args(''.split())
+ >>> parser.parse_args([])
 Namespace(foo=42)
 
 
@@ -1018,9 +1018,9 @@
 ...
 >>> parser = argparse.ArgumentParser(prog='PROG')
 >>> parser.add_argument('foo', type=perfect_square)
- >>> parser.parse_args('9'.split())
+ >>> parser.parse_args(['9'])
 Namespace(foo=9)
- >>> parser.parse_args('7'.split())
+ >>> parser.parse_args(['7'])
 usage: PROG [-h] foo
 PROG: error: argument foo: '7' is not a perfect square
 
@@ -1029,9 +1029,9 @@
 
 >>> parser = argparse.ArgumentParser(prog='PROG')
 >>> parser.add_argument('foo', type=int, choices=range(5, 10))
- >>> parser.parse_args('7'.split())
+ >>> parser.parse_args(['7'])
 Namespace(foo=7)
- >>> parser.parse_args('11'.split())
+ >>> parser.parse_args(['11'])
 usage: PROG [-h] {5,6,7,8,9}
 PROG: error: argument foo: invalid choice: 11 (choose from 5, 6, 7, 8, 9)
 
@@ -1112,7 +1112,7 @@
 ... help='foo the bars before frobbling')
 >>> parser.add_argument('bar', nargs='+',
 ... help='one of the bars to be frobbled')
- >>> parser.parse_args('-h'.split())
+ >>> parser.parse_args(['-h'])
 usage: frobble [-h] [--foo] bar [bar ...]
 
 positional arguments:
@@ -1230,7 +1230,7 @@
 
 >>> parser = argparse.ArgumentParser()
 >>> parser.add_argument('bar')
- >>> parser.parse_args('XXX'.split())
+ >>> parser.parse_args(['XXX'])
 Namespace(bar='XXX')
 
 For optional argument actions, the value of ``dest`` is normally inferred from
@@ -1327,22 +1327,22 @@
 >>> parser = argparse.ArgumentParser(prog='PROG')
 >>> parser.add_argument('-x')
 >>> parser.add_argument('--foo')
- >>> parser.parse_args('-x X'.split())
+ >>> parser.parse_args(['-x', 'X'])
 Namespace(foo=None, x='X')
- >>> parser.parse_args('--foo FOO'.split())
+ >>> parser.parse_args(['--foo', 'FOO'])
 Namespace(foo='FOO', x=None)
 
 For long options (options with names longer than a single character), the option
 and value can also be passed as a single command-line argument, using ``=`` to
 separate them::
 
- >>> parser.parse_args('--foo=FOO'.split())
+ >>> parser.parse_args(['--foo=FOO'])
 Namespace(foo='FOO', x=None)
 
 For short options (options only one character long), the option and its value
 can be concatenated::
 
- >>> parser.parse_args('-xX'.split())
+ >>> parser.parse_args(['-xX'])
 Namespace(foo=None, x='X')
 
 Several short options can be joined together, using only a single ``-`` prefix,
@@ -1352,7 +1352,7 @@
 >>> parser.add_argument('-x', action='store_true')
 >>> parser.add_argument('-y', action='store_true')
 >>> parser.add_argument('-z')
- >>> parser.parse_args('-xyzZ'.split())
+ >>> parser.parse_args(['-xyzZ'])
 Namespace(x=True, y=True, z='Z')
 
 
@@ -1474,7 +1474,7 @@
 ... default=max, help='sum the integers (default: find the max)')
 >>> parser.parse_args(['1', '2', '3', '4'])
 Namespace(accumulate=<built-in function max>, integers=[1, 2, 3, 4])
- >>> parser.parse_args('1 2 3 4 --sum'.split())
+ >>> parser.parse_args(['1', '2', '3', '4', '--sum'])
 Namespace(accumulate=<built-in function sum>, integers=[1, 2, 3, 4])
 
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /