What's the difference between '_io' and 'io'?

The _io module provides the C code that the io module uses internally. The source for it can be found here. You can actually import both io and _io separately:

>>> import _io
>>> import io
>>> _io
<module 'io' (built-in)>  # The fact that this says io instead of _io is a bug (Issue 18602)
>>> io
<module 'io' from '/usr/lib/python3.4/io.py'>
>>> _io.TextIOWrapper
<type '_io.TextIOWrapper'>

This pattern (C-code for modulename provided in _modulename) is actually used for several modules - multiprocessing/_multiprocessing, csv/_csv, etc. Basically all cases where a module has a component that's written in C.


_io is the C implementation part of the io module, io the Python part.

From PEP8:

When an extension module written in C or C++ has an accompanying Python module that provides a higher level (e.g. more object oriented) interface, the C/C++ module has a leading underscore (e.g. _socket).