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

Skip to content

Commit 90e2cd6

Browse files
author
joy
committed
kyclark#1 joy.y
1 parent 8b49d04 commit 90e2cd6

File tree

4 files changed

+245
-0
lines changed

4 files changed

+245
-0
lines changed

01_hello/hello.py

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

01_hello/hello2.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : kakao <kakao@localhost>
4+
Date : 2021-09-28
5+
Purpose: Rock the Casbah
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description='Rock the Casbah',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
19+
parser.add_argument('positional',
20+
metavar='str',
21+
help='A positional argument')
22+
23+
parser.add_argument('-a',
24+
'--arg',
25+
help='A named string argument',
26+
metavar='str',
27+
type=str,
28+
default='')
29+
30+
parser.add_argument('-i',
31+
'--int',
32+
help='A named integer argument',
33+
metavar='int',
34+
type=int,
35+
default=0)
36+
37+
parser.add_argument('-f',
38+
'--file',
39+
help='A readable file',
40+
metavar='FILE',
41+
type=argparse.FileType('rt'),
42+
default=None)
43+
44+
parser.add_argument('-o',
45+
'--on',
46+
help='A boolean flag',
47+
action='store_true')
48+
49+
return parser.parse_args()
50+
51+
52+
# --------------------------------------------------
53+
def main():
54+
"""Make a jazz noise here"""
55+
56+
args = get_args()
57+
str_arg = args.arg
58+
int_arg = args.int
59+
file_arg = args.file
60+
flag_arg = args.on
61+
pos_arg = args.positional
62+
63+
print(f'str_arg = "{str_arg}"')
64+
print(f'int_arg = "{int_arg}"')
65+
print('file_arg = "{}"'.format(file_arg.name if file_arg else ''))
66+
print(f'flag_arg = "{flag_arg}"')
67+
print(f'positional = "{pos_arg}"')
68+
69+
70+
# --------------------------------------------------
71+
if __name__ == '__main__':
72+
main()

01_hello/hello3.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : kakao <kakao@localhost>
4+
Date : 2021-09-28
5+
Purpose: Rock the Casbah
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description='Rock the Casbah',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
19+
parser.add_argument('positional',
20+
metavar='str',
21+
help='A positional argument')
22+
23+
parser.add_argument('-a',
24+
'--arg',
25+
help='A named string argument',
26+
metavar='str',
27+
type=str,
28+
default='')
29+
30+
parser.add_argument('-i',
31+
'--int',
32+
help='A named integer argument',
33+
metavar='int',
34+
type=int,
35+
default=0)
36+
37+
parser.add_argument('-f',
38+
'--file',
39+
help='A readable file',
40+
metavar='FILE',
41+
type=argparse.FileType('rt'),
42+
default=None)
43+
44+
parser.add_argument('-o',
45+
'--on',
46+
help='A boolean flag',
47+
action='store_true')
48+
49+
return parser.parse_args()
50+
51+
52+
# --------------------------------------------------
53+
def main():
54+
"""Make a jazz noise here"""
55+
56+
args = get_args()
57+
str_arg = args.arg
58+
int_arg = args.int
59+
file_arg = args.file
60+
flag_arg = args.on
61+
pos_arg = args.positional
62+
63+
print(f'str_arg = "{str_arg}"')
64+
print(f'int_arg = "{int_arg}"')
65+
print('file_arg = "{}"'.format(file_arg.name if file_arg else ''))
66+
print(f'flag_arg = "{flag_arg}"')
67+
print(f'positional = "{pos_arg}"')
68+
69+
70+
# --------------------------------------------------
71+
if __name__ == '__main__':
72+
main()

01_hello/hello4.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : NowHappy <[email protected]>
4+
Date : 2021-09-28
5+
Purpose: Rock the Casbah
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description='Rock the Casbah',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
19+
parser.add_argument('positional',
20+
metavar='str',
21+
help='A positional argument')
22+
23+
parser.add_argument('-a',
24+
'--arg',
25+
help='A named string argument',
26+
metavar='str',
27+
type=str,
28+
default='')
29+
30+
parser.add_argument('-i',
31+
'--int',
32+
help='A named integer argument',
33+
metavar='int',
34+
type=int,
35+
default=0)
36+
37+
parser.add_argument('-f',
38+
'--file',
39+
help='A readable file',
40+
metavar='FILE',
41+
type=argparse.FileType('rt'),
42+
default=None)
43+
44+
parser.add_argument('-o',
45+
'--on',
46+
help='A boolean flag',
47+
action='store_true')
48+
49+
return parser.parse_args()
50+
51+
52+
# --------------------------------------------------
53+
def main():
54+
"""Make a jazz noise here"""
55+
56+
args = get_args()
57+
str_arg = args.arg
58+
int_arg = args.int
59+
file_arg = args.file
60+
flag_arg = args.on
61+
pos_arg = args.positional
62+
63+
print(f'str_arg = "{str_arg}"')
64+
print(f'int_arg = "{int_arg}"')
65+
print('file_arg = "{}"'.format(file_arg.name if file_arg else ''))
66+
print(f'flag_arg = "{flag_arg}"')
67+
print(f'positional = "{pos_arg}"')
68+
69+
70+
# --------------------------------------------------
71+
if __name__ == '__main__':
72+
main()

0 commit comments

Comments
 (0)