Why the io module object does not have the "RawIOBase" attribute, although I am using python 2.6

I tried to create a class in python using RawIOBase as shown below.

try:
    import io
except ImportError:
    class Serial(PosixSerial, FileLike):
        pass
else:
    class Serial(PosixSerial, io.RawIOBase):
        pass

I tried to run this using Python 2.6, but it displays an error:

AttributeError: the 'module' object does not have the 'RawIOBase' attribute

I read that RawIOBase is supported with Python 2.6 onwards.

+4
source share
1 answer

Make sure you do not have another file with the name io.py. If so, it can mask the module ioin the standard library. You can check which file is loading as a module ioby typing print(io). It should return something like <module 'io' from '/usr/lib/python2.6/io.pyc'>.

, lib, , io.

+6

Source: https://habr.com/ru/post/1539965/


All Articles