diff options
author | Georg Brandl <georg@python.org> | 2009-02-07 12:21:17 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-02-07 12:21:17 (GMT) |
commit | 34feea32058ce9610fbb0357661f80232f80d3e4 (patch) | |
tree | e012633d38b40ac7af3cb981b37ce2324417d1f0 | |
parent | 8e5e438d215f88e586a34fcb7fe867b34852215f (diff) | |
download | cpython-34feea32058ce9610fbb0357661f80232f80d3e4.zip cpython-34feea32058ce9610fbb0357661f80232f80d3e4.tar.gz cpython-34feea32058ce9610fbb0357661f80232f80d3e4.tar.bz2 |
#5174: fix wrong file closing in example.
-rw-r--r-- | Doc/library/xmlrpclib.rst | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/Doc/library/xmlrpclib.rst b/Doc/library/xmlrpclib.rst index 039a8a8..4035f8e 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: |