summaryrefslogtreecommitdiffstats
path: root/Lib/platform.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/platform.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/platform.py')
-rwxr-xr-xLib/platform.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index f7ffd00..b9bc303 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -200,9 +200,8 @@ def _dist_try_harder(distname,version,id):
"""
if os.path.exists('/var/adm/inst-log/info'):
# SuSE Linux stores distribution information in that file
- info = open('/var/adm/inst-log/info').readlines()
distname = 'SuSE'
- for line in info:
+ for line in open('/var/adm/inst-log/info'):
tv = line.split()
if len(tv) == 2:
tag,value = tv
@@ -217,8 +216,7 @@ def _dist_try_harder(distname,version,id):
if os.path.exists('/etc/.installed'):
# Caldera OpenLinux has some infos in that file (thanks to Colin Kong)
- info = open('/etc/.installed').readlines()
- for line in info:
+ for line in open('/etc/.installed'):
pkg = line.split('-')
if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
# XXX does Caldera support non Intel platforms ? If yes,
@@ -327,9 +325,8 @@ def linux_distribution(distname='', version='', id='',
return _dist_try_harder(distname,version,id)
# Read the first line
- f = open('/etc/'+file, 'r')
- firstline = f.readline()
- f.close()
+ with open('/etc/'+file, 'r') as f:
+ firstline = f.readline()
_distname, _version, _id = _parse_release_file(firstline)
if _distname and full_distribution_name: