Close the open file handle using context manager

Signed-off-by: Kevin Jing Qiu <kevin.qiu@points.com>
This commit is contained in:
Kevin Jing Qiu 2017-01-26 14:23:12 -05:00 committed by Joffrey F
parent 951497c0f2
commit a3a9d8944a
1 changed files with 7 additions and 5 deletions

View File

@ -2,6 +2,7 @@ from __future__ import absolute_import
from __future__ import unicode_literals
import codecs
import contextlib
import logging
import os
@ -31,7 +32,8 @@ def env_vars_from_file(filename):
elif not os.path.isfile(filename):
raise ConfigurationError("%s is not a file." % (filename))
env = {}
for line in codecs.open(filename, 'r', 'utf-8'):
with contextlib.closing(codecs.open(filename, 'r', 'utf-8')) as fileobj:
for line in fileobj:
line = line.strip()
if line and not line.startswith('#'):
k, v = split_env(line)