File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments