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 2, 2021
1 parent
c14bd30
commit 050bca1
Showing
2 changed files
with
51 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Author : NowHappy <[email protected]> | ||
Date : 2021-10-02 | ||
Purpose: Rock the Casbah | ||
""" | ||
|
||
import argparse | ||
import os | ||
|
||
|
||
# -------------------------------------------------- | ||
def get_args(): | ||
"""Get command-line arguments""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description='howler (upper-cases input)', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
parser.add_argument('input', | ||
metavar='text', | ||
help='Input string or file') | ||
|
||
parser.add_argument('-o', | ||
'--outfile', | ||
help='Output filename', | ||
metavar='str', | ||
type=argparse.FileType('wt'), | ||
default='') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
# -------------------------------------------------- | ||
def main(): | ||
"""Make a jazz noise here""" | ||
|
||
args = get_args() | ||
str_args = args.input | ||
outfile_args = args.outfile | ||
|
||
if os.path.isfile(args.input): | ||
str_args = open(str_args).read() | ||
|
||
print(f'{str_args.upper()}', file=outfile_args) if outfile_args else print(f'{str_args.upper()}') | ||
|
||
|
||
# -------------------------------------------------- | ||
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
this is some text | ||
this is some more text | ||
test222 |