forked from kyclark/tiny_python_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
joy
committed
Oct 1, 2021
1 parent
8b49d04
commit 7d819f3
Showing
5 changed files
with
246 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Author: NowHappy <[email protected]> | ||
Purpose: Say Hello | ||
""" | ||
|
||
import argparse | ||
|
||
|
||
# --------------------------------------------------- | ||
def get_args(): | ||
"""Get the command-line arguments""" | ||
parser = argparse.ArgumentParser(description='Say Hello') | ||
parser.add_argument('-n', '--name', metavar='name', | ||
default='World', help='Name to greet') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
# --------------------------------------------------- | ||
def main(): | ||
"""happy now""" | ||
args = get_args() | ||
print('Hello, ' + args.name + '!') | ||
|
||
|
||
# --------------------------------------------------- | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Author : kakao <kakao@localhost> | ||
Date : 2021-09-28 | ||
Purpose: Rock the Casbah | ||
""" | ||
|
||
import argparse | ||
|
||
|
||
# -------------------------------------------------- | ||
def get_args(): | ||
"""Get command-line arguments""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description='Rock the Casbah', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
parser.add_argument('positional', | ||
metavar='str', | ||
help='A positional argument') | ||
|
||
parser.add_argument('-a', | ||
'--arg', | ||
help='A named string argument', | ||
metavar='str', | ||
type=str, | ||
default='') | ||
|
||
parser.add_argument('-i', | ||
'--int', | ||
help='A named integer argument', | ||
metavar='int', | ||
type=int, | ||
default=0) | ||
|
||
parser.add_argument('-f', | ||
'--file', | ||
help='A readable file', | ||
metavar='FILE', | ||
type=argparse.FileType('rt'), | ||
default=None) | ||
|
||
parser.add_argument('-o', | ||
'--on', | ||
help='A boolean flag', | ||
action='store_true') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
# -------------------------------------------------- | ||
def main(): | ||
"""Make a jazz noise here""" | ||
|
||
args = get_args() | ||
str_arg = args.arg | ||
int_arg = args.int | ||
file_arg = args.file | ||
flag_arg = args.on | ||
pos_arg = args.positional | ||
|
||
print(f'str_arg = "{str_arg}"') | ||
print(f'int_arg = "{int_arg}"') | ||
print('file_arg = "{}"'.format(file_arg.name if file_arg else '')) | ||
print(f'flag_arg = "{flag_arg}"') | ||
print(f'positional = "{pos_arg}"') | ||
|
||
|
||
# -------------------------------------------------- | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Author : kakao <kakao@localhost> | ||
Date : 2021-09-28 | ||
Purpose: Rock the Casbah | ||
""" | ||
|
||
import argparse | ||
|
||
|
||
# -------------------------------------------------- | ||
def get_args(): | ||
"""Get command-line arguments""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description='Rock the Casbah', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
parser.add_argument('positional', | ||
metavar='str', | ||
help='A positional argument') | ||
|
||
parser.add_argument('-a', | ||
'--arg', | ||
help='A named string argument', | ||
metavar='str', | ||
type=str, | ||
default='') | ||
|
||
parser.add_argument('-i', | ||
'--int', | ||
help='A named integer argument', | ||
metavar='int', | ||
type=int, | ||
default=0) | ||
|
||
parser.add_argument('-f', | ||
'--file', | ||
help='A readable file', | ||
metavar='FILE', | ||
type=argparse.FileType('rt'), | ||
default=None) | ||
|
||
parser.add_argument('-o', | ||
'--on', | ||
help='A boolean flag', | ||
action='store_true') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
# -------------------------------------------------- | ||
def main(): | ||
"""Make a jazz noise here""" | ||
|
||
args = get_args() | ||
str_arg = args.arg | ||
int_arg = args.int | ||
file_arg = args.file | ||
flag_arg = args.on | ||
pos_arg = args.positional | ||
|
||
print(f'str_arg = "{str_arg}"') | ||
print(f'int_arg = "{int_arg}"') | ||
print('file_arg = "{}"'.format(file_arg.name if file_arg else '')) | ||
print(f'flag_arg = "{flag_arg}"') | ||
print(f'positional = "{pos_arg}"') | ||
|
||
|
||
# -------------------------------------------------- | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Author : NowHappy <[email protected]> | ||
Date : 2021-09-28 | ||
Purpose: Rock the Casbah | ||
""" | ||
|
||
import argparse | ||
|
||
|
||
# -------------------------------------------------- | ||
def get_args(): | ||
"""Get command-line arguments""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description='Rock the Casbah', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
parser.add_argument('positional', | ||
metavar='str', | ||
help='A positional argument') | ||
|
||
parser.add_argument('-a', | ||
'--arg', | ||
help='A named string argument', | ||
metavar='str', | ||
type=str, | ||
default='') | ||
|
||
parser.add_argument('-i', | ||
'--int', | ||
help='A named integer argument', | ||
metavar='int', | ||
type=int, | ||
default=0) | ||
|
||
parser.add_argument('-f', | ||
'--file', | ||
help='A readable file', | ||
metavar='FILE', | ||
type=argparse.FileType('rt'), | ||
default=None) | ||
|
||
parser.add_argument('-o', | ||
'--on', | ||
help='A boolean flag', | ||
action='store_true') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
# -------------------------------------------------- | ||
def main(): | ||
"""Make a jazz noise here""" | ||
|
||
args = get_args() | ||
str_arg = args.arg | ||
int_arg = args.int | ||
file_arg = args.file | ||
flag_arg = args.on | ||
pos_arg = args.positional | ||
|
||
print(f'str_arg = "{str_arg}"') | ||
print(f'int_arg = "{int_arg}"') | ||
print('file_arg = "{}"'.format(file_arg.name if file_arg else '')) | ||
print(f'flag_arg = "{flag_arg}"') | ||
print(f'positional = "{pos_arg}"') | ||
|
||
|
||
# -------------------------------------------------- | ||
if __name__ == '__main__': | ||
main() |