Skip to content

Commit 9067d66

Browse files
committed
fixes
1 parent af1650b commit 9067d66

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

17_mad_libs/solution1_regex.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_args():
1616

1717
parser.add_argument('file',
1818
metavar='FILE',
19-
type=argparse.FileType('r'),
19+
type=argparse.FileType('rt'),
2020
help='Input file')
2121

2222
parser.add_argument('-i',
@@ -39,8 +39,7 @@ def main():
3939
blanks = re.findall('(<([^<>]+)>)', text)
4040

4141
if not blanks:
42-
print(f'"{args.file.name}" has no placeholders.', file=sys.stderr)
43-
sys.exit(1)
42+
sys.exit(f'"{args.file.name}" has no placeholders.')
4443

4544
tmpl = 'Give me {} {}: '
4645
for placeholder, pos in blanks:

17_mad_libs/solution2_no_regex.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""Mad Libs"""
33

44
import argparse
5-
import re
65
import sys
76

87

@@ -16,7 +15,7 @@ def get_args():
1615

1716
parser.add_argument('file',
1817
metavar='FILE',
19-
type=argparse.FileType('r'),
18+
type=argparse.FileType('rt'),
2019
help='Input file')
2120

2221
parser.add_argument('-i',
@@ -55,8 +54,7 @@ def main():
5554
if had_placeholders:
5655
print(text)
5756
else:
58-
print(f'"{args.file.name}" has no placeholders.', file=sys.stderr)
59-
sys.exit(1)
57+
sys.exit(f'"{args.file.name}" has no placeholders.')
6058

6159

6260
# --------------------------------------------------
@@ -65,15 +63,15 @@ def find_brackets(text):
6563

6664
start = text.index('<') if '<' in text else -1
6765
stop = text.index('>') if start >= 0 and '>' in text[start + 2:] else -1
68-
return (start, stop) if start >= 0 and stop >= 0 else and balanced None
66+
return (start, stop) if start >= 0 and stop >= 0 else None
6967

7068

7169
# --------------------------------------------------
7270
def test_find_brackets():
7371
"""Test for finding angle brackets"""
7472

75-
assert find_brackets('') == None
76-
assert find_brackets('<>') == None
73+
assert find_brackets('') is None
74+
assert find_brackets('<>') is None
7775
assert find_brackets('<x>') == (0, 2)
7876
assert find_brackets('foo <bar> baz') == (4, 8)
7977

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy