File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ """Apples and Bananas"""
3+
4+ import argparse
5+ import os
6+ import re
7+
8+
9+ # --------------------------------------------------
10+ def get_args ():
11+ """get command-line arguments"""
12+
13+ parser = argparse .ArgumentParser (
14+ description = 'Apples and bananas' ,
15+ formatter_class = argparse .ArgumentDefaultsHelpFormatter )
16+
17+ parser .add_argument ('text' , metavar = 'text' , help = 'Input text or file' )
18+
19+ parser .add_argument ('-v' ,
20+ '--vowel' ,
21+ help = 'The vowel to substitute' ,
22+ metavar = 'vowel' ,
23+ type = str ,
24+ default = 'a' ,
25+ choices = list ('aeiou' ))
26+
27+ args = parser .parse_args ()
28+
29+ if os .path .isfile (args .text ):
30+ args .text = open (args .text ).read ().rstrip ()
31+
32+ return args
33+
34+
35+ # --------------------------------------------------
36+ def main ():
37+ """Make a jazz noise here"""
38+
39+ args = get_args ()
40+ print ('' .join ([new_char (c , args .vowel ) for c in args .text ]))
41+
42+
43+ # --------------------------------------------------
44+ def new_char (char , vowel ):
45+ """Return the given vowel if a char is a vowel else the char"""
46+
47+ return vowel if char in 'aeiou' else \
48+ vowel .upper () if char in 'AEIOU' else char
49+
50+
51+ # --------------------------------------------------
52+ if __name__ == '__main__' :
53+ main ()
You can’t perform that action at this time.
0 commit comments