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