From: Georg Brandl Date: Sat, 7 Feb 2009 12:21:17 +0000 (+0000) Subject: #5174: fix wrong file closing in example. X-Git-Tag: v2.7a1~2087 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34feea32058ce9610fbb0357661f80232f80d3e4;p=thirdparty%2FPython%2Fcpython.git #5174: fix wrong file closing in example. --- diff --git a/Doc/library/xmlrpclib.rst b/Doc/library/xmlrpclib.rst index 039a8a8d5ace..4035f8eeba63 100644 --- a/Doc/library/xmlrpclib.rst +++ b/Doc/library/xmlrpclib.rst @@ -318,9 +318,8 @@ XMLRPC:: import xmlrpclib def python_logo(): - handle = open("python_logo.jpg") - return xmlrpclib.Binary(handle.read()) - handle.close() + with open("python_logo.jpg") as handle: + return xmlrpclib.Binary(handle.read()) server = SimpleXMLRPCServer(("localhost", 8000)) print "Listening on port 8000..." @@ -333,9 +332,8 @@ The client gets the image and saves it to a file:: import xmlrpclib proxy = xmlrpclib.ServerProxy("http://localhost:8000/") - handle = open("fetched_python_logo.jpg", "w") - handle.write(proxy.python_logo().data) - handle.close() + with open("fetched_python_logo.jpg", "w") as handle: + handle.write(proxy.python_logo().data) .. _fault-objects: