Use the with keyword dealing with file objects

Change-Id: I4c6a36483d4780dfda01b888939f4c959bcefd62
This commit is contained in:
fengchaoyang 2016-12-08 11:10:33 +08:00 committed by Dougal Matthews
parent dce3be2831
commit d7fcd4e813
1 changed files with 3 additions and 4 deletions

View File

@ -39,10 +39,9 @@ def get_mapping():
delete_comment(value)
if '_comment' in map_part:
del map_part['_comment']
mapping = json.loads(open(pkg.resource_filename(
version.version_info.package,
MAPPING_PATH)).read())
package = version.version_info.package
with open(pkg.resource_filename(package, MAPPING_PATH)) as fh:
mapping = json.load(fh)
for k, v in mapping.items():
if isinstance(v, dict):