Search code examples
python-2.7printingioerror

python print with IOError: [Errno 0] Error


ll=[]
for ii in range(26):
    ll.append(chr(97+ii))

for ii in range(10000):
    print ll

When I print like this, it will report some error, Why?!

['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r'Traceback (most recent call last):
  File "e:/czh/python/test.py", line 7, in <module>
    print ll
IOError: [Errno 0] Error

Solution

  • This is a Windows bug that was fixed with Windows 10 Version 1803. (see https://bugs.python.org/issue32245 and https://github.com/Microsoft/vscode/issues/36630#issuecomment-385759625 )

    It affects Python 3.6+ when using code paths that call WriteFile, i.e. os.write and legacy standard I/O mode, and also always affects Python 2.7 and Python 3.5.