Skip to content

Commit 0a03b18

Browse files
committed
first solution 05
1 parent da0d2ba commit 0a03b18

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎05_howler/howler.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#! /usr/bin/env python3
2+
3+
import argparse
4+
import os
5+
6+
import sys
7+
8+
def get_args():
9+
parser = argparse.ArgumentParser(
10+
prog='Howler.py',
11+
description='Howler (upper-cases input)')
12+
13+
parser.add_argument('text', type=str, help='Inpyt string or file')
14+
parser.add_argument('-o', '--outfile',
15+
metavar='str',
16+
dest='outfile',
17+
help='Output filename (default: ',
18+
default = '')
19+
20+
return parser.parse_args()
21+
22+
23+
def main():
24+
25+
args = get_args()
26+
27+
text = args.text
28+
of_path = args.outfile
29+
30+
31+
if os.path.isfile(text):
32+
#print('is file', text)
33+
in_file = open(text)
34+
out_text = in_file.read().upper()
35+
in_file.close()
36+
else:
37+
out_text = text.upper()
38+
39+
if of_path != '':
40+
out_file = open(of_path, 'wt')
41+
else:
42+
out_file = sys.stdout
43+
44+
print(out_text, file = out_file)
45+
46+
if out_file != sys.stdout:
47+
out_file.close()
48+
49+
50+
51+
if __name__ == '__main__':
52+
main()
53+
54+
55+
56+

0 commit comments

Comments
 (0)