Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I tried the code below. The f is of type _io.TextIOWrapper, but I cannot find any help info about this type. While there does exsist another similar type io.TextIOWrapper.

>>> f=open("c:\setup.log","r")
>>> type(f)
<class '_io.TextIOWrapper'>
>>> help(_io.TextIOWrapper)
Traceback (most recent call last):
  File "<pyshell#204>", line 1, in <module>
    help(_io.TextIOWrapper)
NameError: name '_io' is not defined
>>> help(io.TextIOWrapper)
Help on class TextIOWrapper in module io:

My questions are:

  • If the name _io is not defined, how can I use it?

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

like image 485
smwikipedia Avatar asked Oct 06 '14 01:10

smwikipedia


People also ask

What is difference between memory mapped IO and IO mapped IO?

The main difference between memory mapped IO and IO mapped IO is that the memory mapped IO uses the same address space for both memory and IO device while the IO mapped IO uses two separate address spaces for memory and IO device.

What do you mean by IO mapped IO?

A kind of interfacing in which we assign an 8-bit address value to the input/output devices which can be accessed using IN and OUT instruction is called I/O Mapped I/O Interfacing.


1 Answers

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.

like image 65
dano Avatar answered Sep 19 '22 08:09

dano