summaryrefslogtreecommitdiffstats
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r--Lib/pkgutil.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index 0f783de..8fa8405 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -349,9 +349,8 @@ class ImpLoader:
self.file.close()
elif mod_type==imp.PY_COMPILED:
if os.path.exists(self.filename[:-1]):
- f = open(self.filename[:-1], 'r')
- self.source = f.read()
- f.close()
+ with open(self.filename[:-1], 'r') as f:
+ self.source = f.read()
elif mod_type==imp.PKG_DIRECTORY:
self.source = self._get_delegate().get_source()
return self.source
@@ -591,12 +590,12 @@ def extend_path(path, name):
sys.stderr.write("Can't open %s: %s\n" %
(pkgfile, msg))
else:
- for line in f:
- line = line.rstrip('\n')
- if not line or line.startswith('#'):
- continue
- path.append(line) # Don't check for existence!
- f.close()
+ with f:
+ for line in f:
+ line = line.rstrip('\n')
+ if not line or line.startswith('#'):
+ continue
+ path.append(line) # Don't check for existence!
return path