diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-01-30 02:19:14 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-01-30 02:19:14 (GMT) |
commit | f49c67a75ba548341727fac73d82c0534738c360 (patch) | |
tree | 9b786840efa84dc508bae0c4045aec2091101174 /Doc | |
parent | 533e5568ff9b847e3ea6dcfd25247777aa9039bd (diff) | |
download | cpython-f49c67a75ba548341727fac73d82c0534738c360.zip cpython-f49c67a75ba548341727fac73d82c0534738c360.tar.gz cpython-f49c67a75ba548341727fac73d82c0534738c360.tar.bz2 |
Merged revisions 77838 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r77838 | victor.stinner | 2010-01-30 03:16:55 +0100 (sam., 30 janv. 2010) | 4 lines
#7801: fix xmlrpclib binary example, open the picture in binary mode
Use also the with syntax (consistent with python trunk example).
........
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/xmlrpc.client.rst | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst index 52d236e..1bcc423 100644 --- a/Doc/library/xmlrpc.client.rst +++ b/Doc/library/xmlrpc.client.rst @@ -283,9 +283,8 @@ XMLRPC:: import xmlrpc.client def python_logo(): - handle = open("python_logo.jpg") - return xmlrpc.client.Binary(handle.read()) - handle.close() + with open("python_logo.jpg", "rb") as handle: + return xmlrpc.client.Binary(handle.read()) server = SimpleXMLRPCServer(("localhost", 8000)) print("Listening on port 8000...") @@ -298,9 +297,8 @@ The client gets the image and saves it to a file:: import xmlrpc.client proxy = xmlrpc.client.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", "wb") as handle: + handle.write(proxy.python_logo().data) .. _fault-objects: |