summaryrefslogtreecommitdiffstats
path: root/Lib/keyword.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-09-03 19:52:03 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-09-03 19:52:03 (GMT)
commit7dde792e62c8adeaf5d633dc89e18d16067add8e (patch)
tree41852c7a810c87d0a804d19f7ba6bc4266b1d66c /Lib/keyword.py
parent24e561ae0473ad6f46709e38ed8ebc97d89fc55e (diff)
downloadcpython-7dde792e62c8adeaf5d633dc89e18d16067add8e.zip
cpython-7dde792e62c8adeaf5d633dc89e18d16067add8e.tar.gz
cpython-7dde792e62c8adeaf5d633dc89e18d16067add8e.tar.bz2
Use a context manager for some file objects.
Diffstat (limited to 'Lib/keyword.py')
-rwxr-xr-xLib/keyword.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/Lib/keyword.py b/Lib/keyword.py
index a5974b5..a3788a6 100755
--- a/Lib/keyword.py
+++ b/Lib/keyword.py
@@ -61,21 +61,19 @@ def main():
else: optfile = "Lib/keyword.py"
# scan the source file for keywords
- fp = open(iptfile)
- strprog = re.compile('"([^"]+)"')
- lines = []
- for line in fp:
- if '{1, "' in line:
- match = strprog.search(line)
- if match:
- lines.append(" '" + match.group(1) + "',\n")
- fp.close()
+ with open(iptfile) as fp:
+ strprog = re.compile('"([^"]+)"')
+ lines = []
+ for line in fp:
+ if '{1, "' in line:
+ match = strprog.search(line)
+ if match:
+ lines.append(" '" + match.group(1) + "',\n")
lines.sort()
# load the output skeleton from the target
- fp = open(optfile)
- format = fp.readlines()
- fp.close()
+ with open(optfile) as fp:
+ format = fp.readlines()
# insert the lines of keywords
try: