What is the difference between StringIO and io.StringIO in Python2.7?

http://docs.python.org/library/io.html#io.StringIO

http://docs.python.org/library/stringio.html

I see this.

An in-memory stream for unicode text. It inherits TextIOWrapper.

This module implements a file-like class, StringIO, that reads and writes a string buffer (also known as memory files).

io.StringIO is a class. It handles Unicode. It reflects the preferred Python 3 library structure.

StringIO.StringIO is a class. It handles strings. It reflects the legacy Python 2 library structure.

What should be preferred?

Always move forward toward the new library organization. The io.open should be used to replace the built-in Unicode-unaware open.

Forward. Move forward.

Leave a Comment