Skip to content

Commit 8e33285

Browse files
authored
Use BytesIO instead of StringIO (#4376)
Use BytesIO instead of StringIO
2 parents 455a113 + 1f58028 commit 8e33285

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

docs/handbook/tutorial.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,17 @@ Reading from an open file
464464
with open("hopper.ppm", "rb") as fp:
465465
im = Image.open(fp)
466466

467-
To read an image from string data, use the :py:class:`~StringIO.StringIO`
467+
To read an image from binary data, use the :py:class:`~io.BytesIO`
468468
class:
469469

470-
Reading from a string
471-
^^^^^^^^^^^^^^^^^^^^^
470+
Reading from binary data
471+
^^^^^^^^^^^^^^^^^^^^^^^^
472472

473473
::
474474

475475
from PIL import Image
476-
import StringIO
477-
im = Image.open(StringIO.StringIO(buffer))
476+
import io
477+
im = Image.open(io.BytesIO(buffer))
478478

479479
Note that the library rewinds the file (using ``seek(0)``) before reading the
480480
image header. In addition, seek will also be used when the image data is read

0 commit comments

Comments
 (0)