Skip to content

Commit f9488f7

Browse files
authored
Merge pull request #1 from charlieroth/main
Chapter 1 Complete
2 parents f9151ba + f39f9e7 commit f9488f7

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

01_hello/hello.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
"""
4+
Author: Charles Roth <charlieroth4@icloud.com>
5+
Purpose: Say hello
6+
"""
7+
8+
9+
def get_args():
10+
"""Get the command line args"""
11+
12+
parser = argparse.ArgumentParser(description='Say hello')
13+
parser.add_argument(
14+
'-n',
15+
'--name',
16+
metavar='name',
17+
default='World',
18+
help='Name to greet'
19+
)
20+
return parser.parse_args()
21+
22+
23+
def main():
24+
"""Do the damn thing"""
25+
26+
args = get_args()
27+
print('Hello, ' + args.name + '!')
28+
29+
30+
if __name__ == '__main__':
31+
main()

01_hello/hello04_argparse_positional.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python3
22
# Purpose: Say hello
3-
43
import argparse
5-
64
parser = argparse.ArgumentParser(description='Say hello')
75
parser.add_argument('name', help='Name to greet')
86
args = parser.parse_args()

0 commit comments

Comments
 (0)