From 1f58028173e1e31103eac8427c26467c957e0f7f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 21 Jan 2020 23:21:57 +1100 Subject: [PATCH] Use BytesIO instead of StringIO [ci skip] --- docs/handbook/tutorial.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/handbook/tutorial.rst b/docs/handbook/tutorial.rst index 63030de21..040216c20 100644 --- a/docs/handbook/tutorial.rst +++ b/docs/handbook/tutorial.rst @@ -464,17 +464,17 @@ Reading from an open file with open("hopper.ppm", "rb") as fp: im = Image.open(fp) -To read an image from string data, use the :py:class:`~StringIO.StringIO` +To read an image from binary data, use the :py:class:`~io.BytesIO` class: -Reading from a string -^^^^^^^^^^^^^^^^^^^^^ +Reading from binary data +^^^^^^^^^^^^^^^^^^^^^^^^ :: from PIL import Image - import StringIO - im = Image.open(StringIO.StringIO(buffer)) + import io + im = Image.open(io.BytesIO(buffer)) Note that the library rewinds the file (using ``seek(0)``) before reading the image header. In addition, seek will also be used when the image data is read