mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
modernize some modules' code by using with statement around open()
This commit is contained in:
parent
fd6e6cfa29
commit
2f50aaf2ff
14 changed files with 50 additions and 89 deletions
|
@ -86,15 +86,13 @@ class Grammar(object):
|
|||
|
||||
def dump(self, filename):
|
||||
"""Dump the grammar tables to a pickle file."""
|
||||
f = open(filename, "wb")
|
||||
pickle.dump(self.__dict__, f, 2)
|
||||
f.close()
|
||||
with open(filename, "wb") as f:
|
||||
pickle.dump(self.__dict__, f, 2)
|
||||
|
||||
def load(self, filename):
|
||||
"""Load the grammar tables from a pickle file."""
|
||||
f = open(filename, "rb")
|
||||
d = pickle.load(f)
|
||||
f.close()
|
||||
with open(filename, "rb") as f:
|
||||
d = pickle.load(f)
|
||||
self.__dict__.update(d)
|
||||
|
||||
def copy(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue