File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import sys
77
88def 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
2329def 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
5143if __name__ == '__main__' :
5244 main ()
You can’t perform that action at this time.
0 commit comments