Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36572e3

Browse files
committed
ch03: modify program to align help message
1 parent 2d8bf0e commit 36572e3

File tree

1 file changed

+6
-39
lines changed

1 file changed

+6
-39
lines changed

03_picnic/picnic.py

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,9 @@ def get_args():
1717
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
1818
)
1919

20-
parser.add_argument("positional", metavar="str", help="A positional argument")
20+
parser.add_argument("positional", metavar="str", help="Item(s) to bring")
2121

22-
parser.add_argument(
23-
"-a",
24-
"--arg",
25-
help="A named string argument",
26-
metavar="str",
27-
type=str,
28-
default="",
29-
)
30-
31-
parser.add_argument(
32-
"-i",
33-
"--int",
34-
help="A named integer argument",
35-
metavar="int",
36-
type=int,
37-
default=0,
38-
)
39-
40-
parser.add_argument(
41-
"-f",
42-
"--file",
43-
help="A readable file",
44-
metavar="FILE",
45-
type=argparse.FileType("rt"),
46-
default=None,
47-
)
48-
49-
parser.add_argument("-o", "--on", help="A boolean flag", action="store_true")
22+
parser.add_argument("-s", "--sorted", help="Sort the items", action="store_true")
5023

5124
return parser.parse_args()
5225

@@ -56,17 +29,11 @@ def main():
5629
"""Make a jazz noise here"""
5730

5831
args = get_args()
59-
str_arg = args.arg
60-
int_arg = args.int
61-
file_arg = args.file
62-
flag_arg = args.on
63-
pos_arg = args.positional
32+
sort_flag = args.on
33+
items = args.str
6434

65-
print(f'str_arg = "{str_arg}"')
66-
print(f'int_arg = "{int_arg}"')
67-
print('file_arg = "{}"'.format(file_arg.name if file_arg else ""))
68-
print(f'flag_arg = "{flag_arg}"')
69-
print(f'positional = "{pos_arg}"')
35+
print(f'flag_arg = "{sort_flag}"')
36+
print(f'positional = "{items}"')
7037

7138

7239
# --------------------------------------------------

0 commit comments

Comments
 (0)