use with instead of try..finally, add forward references to still-unwritten Files chapter

This commit is contained in:
Mark Pilgrim
2009-07-09 01:21:14 -04:00
parent 83c4c0528c
commit 3478b62a6d
3 changed files with 18 additions and 24 deletions
+1 -4
View File
@@ -15,14 +15,11 @@ def build_match_and_apply_functions(pattern, search, replace):
return [matches_rule, apply_rule]
rules = []
pattern_file = open('plural4-rules.txt')
try:
with open('plural4-rules.txt') as pattern_file:
for line in pattern_file:
pattern, search, replace = line.split(None, 3)
rules.append(build_match_and_apply_functions(
pattern, search, replace))
finally:
pattern_file.close()
def plural(noun):
for matches_rule, apply_rule in rules:
+4 -3
View File
@@ -15,9 +15,10 @@ def build_match_and_apply_functions(pattern, search, replace):
return [matches_rule, apply_rule]
def rules():
for line in open('plural5-rules.txt'):
pattern, search, replace = line.split(None, 3)
yield build_match_and_apply_functions(pattern, search, replace)
with open('plural5-rules.txt') as pattern_file:
for line in pattern_file:
pattern, search, replace = line.split(None, 3)
yield build_match_and_apply_functions(pattern, search, replace)
def plural(noun):
for matches_rule, apply_rule in rules():