diff --git a/python-package/lightgbm/__init__.py b/python-package/lightgbm/__init__.py
index <HASH>..<HASH> 100644
--- a/python-package/lightgbm/__init__.py
+++ b/python-package/lightgbm/__init__.py
@@ -27,7 +27,8 @@ except ImportError:
 dir_path = os.path.dirname(os.path.realpath(__file__))
 
 if os.path.isfile(os.path.join(dir_path, 'VERSION.txt')):
-    __version__ = open(os.path.join(dir_path, 'VERSION.txt')).read().strip()
+    with open(os.path.join(dir_path, 'VERSION.txt')) as version_file:
+        __version__ = version_file.read().strip()
 
 __all__ = ['Dataset', 'Booster',
            'train', 'cv',
[python] Minor fix: close open file pointer (#<I>)