Skip to content

Commit 4235731

Browse files
committed
Consistently use with open() in all examples
1 parent cc90f66 commit 4235731

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

source/development.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ There are a few techniques to store the version in your project code without dup
155155
from `pip setup.py <https://github.com/pypa/pip/blob/1.5.6/setup.py#L33>`_)::
156156

157157
def read(*names, **kwargs):
158-
return io.open(
158+
with io.open(
159159
os.path.join(os.path.dirname(__file__), *names),
160160
encoding=kwargs.get("encoding", "utf8")
161-
).read()
161+
) as fp:
162+
return fp.read()
162163

163164
def find_version(*file_paths):
164165
version_file = read(*file_paths)
@@ -213,8 +214,8 @@ There are a few techniques to store the version in your project code without dup
213214

214215
::
215216

216-
version_file = open(os.path.join(mypackage_root_dir, 'VERSION'))
217-
version = version_file.read().strip()
217+
with open(os.path.join(mypackage_root_dir, 'VERSION')) as version_file:
218+
version = version_file.read().strip()
218219

219220
An advantage with this technique is that it's not specific to Python. Any
220221
tool can read the version.

0 commit comments

Comments
 (0)