]> granicus.if.org Git - python/commitdiff
#5174: fix wrong file closing in example.
authorGeorg Brandl <georg@python.org>
Sat, 7 Feb 2009 12:21:17 +0000 (12:21 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 7 Feb 2009 12:21:17 +0000 (12:21 +0000)
Doc/library/xmlrpclib.rst

index 039a8a8d5ace83fcb05b0904d364c7189db62f5f..4035f8eeba639709bfd78e431bf46d5d1a2e1f90 100644 (file)
@@ -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: