Skip to content

Commit 5ce2d01

Browse files
author
joy
committed
kyclark#8 joy.y
1 parent f12667f commit 5ce2d01

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

08_apples_and_bananas/apples.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : NowHappy <[email protected]>
4+
Date : 2021-10-06
5+
Purpose: Apples and bananas
6+
"""
7+
8+
import argparse
9+
import os
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description='Apples and bananas',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
19+
parser.add_argument('text',
20+
metavar='text',
21+
help='Input text or file')
22+
23+
parser.add_argument('-v',
24+
'--vowel',
25+
help='The vowel to substitute',
26+
metavar='vowel',
27+
choices=list('aeiou'),
28+
type=str,
29+
default='a')
30+
31+
return parser.parse_args()
32+
33+
34+
# --------------------------------------------------
35+
def main():
36+
"""Make a jazz noise here"""
37+
38+
args = get_args()
39+
vowel = args.vowel
40+
41+
# dictionary = { 'a' : vowel, 'e' : vowel, 'i': vowel, 'o': vowel, 'u': vowel, 'A' : vowel.upper(), 'E': vowel.upper(), 'I': vowel.upper(), 'O': vowel.upper(), 'U': vowel.upper() }
42+
43+
trans = str.maketrans('aeiouAEIOU', vowel * 5 + vowel.upper() * 5) # == str.maketrans(dictionary)
44+
45+
if os.path.isfile(args.text):
46+
fh = open(args.text, 'rt')
47+
for line in fh:
48+
print(f'{line.rstrip().translate(trans)}')
49+
else:
50+
print(f'{args.text.translate(trans)}')
51+
52+
53+
# --------------------------------------------------
54+
if __name__ == '__main__':
55+
main()

0 commit comments

Comments
 (0)