Skip to content

Commit c6305fa

Browse files
committed
one singular sensation
1 parent d255992 commit c6305fa

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

appendix_argparse/one_arg.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
"""A single positional argument"""
3+
4+
import argparse
5+
6+
7+
# --------------------------------------------------
8+
def get_args():
9+
"""Get command-line arguments"""
10+
11+
parser = argparse.ArgumentParser(
12+
description='A single positional argument',
13+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
14+
15+
parser.add_argument('name', metavar='name', help='The name to greet')
16+
17+
return parser.parse_args()
18+
19+
20+
# --------------------------------------------------
21+
def main():
22+
"""Make a jazz noise here"""
23+
24+
args = get_args()
25+
print('Hello, ' + args.name + '!')
26+
27+
28+
# --------------------------------------------------
29+
if __name__ == '__main__':
30+
main()

0 commit comments

Comments
 (0)