python – How to use StringIO in Python3?

python – How to use StringIO in Python3?

when i write import StringIO it says there is no such module.

From What’s New In Python 3.0:

The StringIO and cStringIO modules are gone. Instead, import the io
module and use io.StringIO or io.BytesIO for text and data


A possibly useful method of fixing some Python 2 code to also work in Python 3 (caveat emptor):

    from StringIO import StringIO ## for Python 2
except ImportError:
    from io import StringIO ## for Python 3

Note: This example may be tangential to the main issue of the question and is included only as something to consider when generically addressing the missing StringIO module. For a more direct solution the message TypeError: Cant convert bytes object to str implicitly, see this answer.

In my case I have used:

from io import StringIO

python – How to use StringIO in Python3?

On Python 3 numpy.genfromtxt expects a bytes stream. Use the following:


Leave a Reply

Your email address will not be published. Required fields are marked *