Skip to content

Commit c9c71b6

Browse files
committed
ch05: Infile solution
1 parent 3561307 commit c9c71b6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

05_howler/howler.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import argparse
9+
import os
910

1011

1112
# --------------------------------------------------
@@ -31,15 +32,20 @@ def main():
3132
"""Process the arguments"""
3233

3334
args = get_args()
34-
outfile_arg = args.outfile
35-
input_arg = args.input
3635

37-
if outfile_arg != "":
38-
out_fh = open(outfile_arg, "wt")
39-
out_fh.write(input_arg.upper())
36+
if os.path.isfile(args.input):
37+
in_fh = open(args.input)
38+
input_text = in_fh.read()
39+
in_fh.close()
40+
else:
41+
input_text = args.input
42+
43+
if args.outfile != "":
44+
out_fh = open(args.outfile, "wt")
45+
out_fh.write(input_text.upper())
4046
out_fh.close()
4147
else:
42-
print(input_arg.upper())
48+
print(input_text.upper())
4349

4450

4551
# --------------------------------------------------

0 commit comments

Comments
 (0)