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
+ """
3
+ Author : Johan Runesson <[email protected] >
4
+ Date : 2020-08-04
5
+ Purpose: Apples and bananas
6
+ """
7
+
8
+ import argparse
9
+ import os
10
+
11
+
12
+ # --------------------------------------------------
13
+ def get_args ():
14
+ """Get command-line arguments"""
15
+
16
+ parser = argparse .ArgumentParser (
17
+ description = 'Apples and bananas' ,
18
+ formatter_class = argparse .ArgumentDefaultsHelpFormatter )
19
+
20
+ parser .add_argument ('text' , metavar = 'text' , help = 'Input text or file' )
21
+
22
+ parser .add_argument ('-v' ,
23
+ '--vowel' ,
24
+ help = 'The vowel to substitute' ,
25
+ metavar = 'vowel' ,
26
+ type = str ,
27
+ choices = list ('aeiou' ),
28
+ default = 'a' )
29
+
30
+ args = parser .parse_args ()
31
+
32
+ if os .path .isfile (args .text ):
33
+ args .text = open (args .text ).read ().rstrip ()
34
+
35
+ return args
36
+
37
+
38
+ # --------------------------------------------------
39
+ def main ():
40
+ """Start things up"""
41
+
42
+ args = get_args ()
43
+ text = args .text
44
+ vowel = args .vowel
45
+
46
+ new_text = text .translate (str .maketrans ('aeiouAEIOU' , vowel * 5 + vowel .upper () * 5 ));
47
+
48
+ print (new_text )
49
+
50
+
51
+ # --------------------------------------------------
52
+ if __name__ == '__main__' :
53
+ main ()
You can’t perform that action at this time.
0 commit comments