summaryrefslogtreecommitdiffstats
path: root/Lib/pstats.py
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2013-02-12 01:04:27 (GMT)
committerGiampaolo Rodola' <g.rodola@gmail.com>2013-02-12 01:04:27 (GMT)
commit2f50aaf2ff427fb713e82699a6dcbeeb038b10c2 (patch)
tree0e2c24897b8918f19d8504915ccebd466c0bbd92 /Lib/pstats.py
parentfd6e6cfa29b2289e711dc7f57f36897c78899ee7 (diff)
downloadcpython-2f50aaf2ff427fb713e82699a6dcbeeb038b10c2.zip
cpython-2f50aaf2ff427fb713e82699a6dcbeeb038b10c2.tar.gz
cpython-2f50aaf2ff427fb713e82699a6dcbeeb038b10c2.tar.bz2
modernize some modules' code by using with statement around open()
Diffstat (limited to 'Lib/pstats.py')
-rw-r--r--Lib/pstats.py10
1 files changed, 3 insertions, 7 deletions
diff --git a/Lib/pstats.py b/Lib/pstats.py
index 7cf000f..e1ec355 100644
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -93,9 +93,8 @@ class Stats:
self.stats = {}
return
elif isinstance(arg, str):
- f = open(arg, 'rb')
- self.stats = marshal.load(f)
- f.close()
+ with open(arg, 'rb') as f:
+ self.stats = marshal.load(f)
try:
file_stats = os.stat(arg)
arg = time.ctime(file_stats.st_mtime) + " " + arg
@@ -149,11 +148,8 @@ class Stats:
def dump_stats(self, filename):
"""Write the profile data to a file we know how to load back."""
- f = open(filename, 'wb')
- try:
+ with open(filename, 'wb') as f:
marshal.dump(self.stats, f)
- finally:
- f.close()
# list the tuple indices and directions for sorting,
# along with some printable description