Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 757db83

Browse files
author
Victor Stinner
committed
#7801: fix xmlrpclib binary example, open the picture in binary mode
Use also the with syntax (consistent with python trunk example).
1 parent 66da2f3 commit 757db83

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

Doc/library/xmlrpc.client.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,8 @@ XMLRPC::
283283
import xmlrpc.client
284284

285285
def python_logo():
286-
handle = open("python_logo.jpg")
287-
return xmlrpc.client.Binary(handle.read())
288-
handle.close()
286+
with open("python_logo.jpg", "rb") as handle:
287+
return xmlrpc.client.Binary(handle.read())
289288

290289
server = SimpleXMLRPCServer(("localhost", 8000))
291290
print("Listening on port 8000...")
@@ -298,9 +297,8 @@ The client gets the image and saves it to a file::
298297
import xmlrpc.client
299298

300299
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
301-
handle = open("fetched_python_logo.jpg", "w")
302-
handle.write(proxy.python_logo().data)
303-
handle.close()
300+
with open("fetched_python_logo.jpg", "wb") as handle:
301+
handle.write(proxy.python_logo().data)
304302

305303
.. _fault-objects:
306304

0 commit comments

Comments
 (0)