Skip to content

Commit addcca0

Browse files
committed
refactored 05
1 parent 0a03b18 commit addcca0

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

05_howler/howler.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
import sys
77

88
def get_args():
9+
""" Get command-line arguments"""
10+
911
parser = argparse.ArgumentParser(
1012
prog='Howler.py',
1113
description='Howler (upper-cases input)')
1214

13-
parser.add_argument('text', type=str, help='Inpyt string or file')
15+
parser.add_argument('text',
16+
metavar='text',
17+
type=str,
18+
help='Inpyt string or file')
19+
1420
parser.add_argument('-o', '--outfile',
1521
metavar='str',
1622
dest='outfile',
@@ -21,32 +27,18 @@ def get_args():
2127

2228

2329
def main():
30+
""" program entry point """
2431

2532
args = get_args()
2633

2734
text = args.text
2835
of_path = args.outfile
2936

37+
out_text = open(text).read().rstrip() if os.path.isfile(text) else text
3038

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-
39+
out_file = open(of_path, 'wt') if of_path else sys.stdout
4940

41+
print(out_text.upper(), file = out_file)
5042

5143
if __name__ == '__main__':
5244
main()

0 commit comments

Comments
 (0)