# HG changeset patch # Parent dbf90175ea50a85257a9830d8e2fbd6b507ea8bc Issue #20598: Replace trivial split() calls with lists in argparse docs diff -r dbf90175ea50 Doc/library/argparse.rst --- a/Doc/library/argparse.rst Fri Jan 29 04:06:49 2016 +0000 +++ b/Doc/library/argparse.rst Sun Feb 14 07:24:35 2016 +0000 @@ -726,7 +726,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 store the values ``True`` and @@ -765,7 +765,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 @@ -840,11 +840,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 @@ -880,9 +880,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 @@ -936,9 +936,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 @@ -957,9 +957,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) @@ -1016,9 +1016,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 @@ -1027,9 +1027,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) @@ -1110,7 +1110,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: @@ -1228,7 +1228,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 @@ -1325,22 +1325,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, @@ -1350,7 +1350,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') @@ -1472,7 +1472,7 @@ ... default=max, help='sum the integers (default: find the max)') >>> parser.parse_args(['1', '2', '3', '4']) Namespace(accumulate=, integers=[1, 2, 3, 4]) - >>> parser.parse_args('1 2 3 4 --sum'.split()) + >>> parser.parse_args(['1', '2', '3', '4', '--sum']) Namespace(accumulate=, integers=[1, 2, 3, 4])