Skip to content

Commit 51ce15b

Browse files
author
georg.brandl
committed
#5174: fix wrong file closing in example.
git-svn-id: http://svn.python.org/projects/python/trunk@69409 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 2747972 commit 51ce15b

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

Doc/library/xmlrpclib.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,8 @@ XMLRPC::
318318
import xmlrpclib
319319

320320
def python_logo():
321-
handle = open("python_logo.jpg")
322-
return xmlrpclib.Binary(handle.read())
323-
handle.close()
321+
with open("python_logo.jpg") as handle:
322+
return xmlrpclib.Binary(handle.read())
324323

325324
server = SimpleXMLRPCServer(("localhost", 8000))
326325
print "Listening on port 8000..."
@@ -333,9 +332,8 @@ The client gets the image and saves it to a file::
333332
import xmlrpclib
334333

335334
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
336-
handle = open("fetched_python_logo.jpg", "w")
337-
handle.write(proxy.python_logo().data)
338-
handle.close()
335+
with open("fetched_python_logo.jpg", "w") as handle:
336+
handle.write(proxy.python_logo().data)
339337

340338
.. _fault-objects:
341339

0 commit comments

Comments
 (0)