Skip to content

Commit acafffd

Browse files
committed
gh-130132: add an explicit close() call to urlopen examples without with
1 parent 51d4bf1 commit acafffd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Doc/library/urllib.request.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,10 @@ It is also possible to achieve the same result without using the
12491249

12501250
>>> import urllib.request
12511251
>>> f = urllib.request.urlopen('http://www.python.org/')
1252-
>>> print(f.read(100).decode('utf-8'))
1252+
>>> try:
1253+
... print(f.read(100).decode('utf-8'))
1254+
... finally:
1255+
... f.close()
12531256
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
12541257
"http://www.w3.org/TR/xhtml1/DTD/xhtm
12551258

0 commit comments

Comments
 (0)