Python 2.7 python打印带IOError:[Errno 0]错误

Python 2.7 python打印带IOError:[Errno 0]错误,python-2.7,printing,ioerror,Python 2.7,Printing,Ioerror,当我这样打印时,它会报告一些错误,为什么 ll=[] for ii in range(26): ll.append(chr(97+ii)) for ii in range(10000): print ll ['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'

当我这样打印时,它会报告一些错误,为什么

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

for ii in range(10000):
    print ll
['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'回溯(最后一次调用):
文件“e:/czh/python/test.py”,第7行,在
打印ll
IOError:[Errno 0]错误

这是一个Windows错误,已在Windows 10版本1803中修复。(请参阅和)


当使用调用WriteFile的代码路径时,它会影响Python 3.6+,即
os.write
和传统标准i/O模式,并且始终会影响Python 2.7和Python 3.5。

另一个答案:

我在Python 2.7.18中也遇到了同样的问题(v2.7.18:8d21aa21f2,2020年4月20日,13:25:05)[MSC v.1500 64位(AMD64)]

当我想处理一些包含汉字的文本时,我遇到了这个问题

核心代码是:

content=fp.read().strip().strip(“\n”).split(“\n”)#fp是一个打开的文件obj
line=“”.join([1,4,7,10,13,16]]中x的[content[x]
打印(行)
正确的方法是:在iter之前使用unicode而不是str(utf-8)

content=fp.read().strip().strip(“\n”).decode(“utf-8”).split(\n”)#fp是一个打开的文件obj
line=“”.join([1,4,7,10,13,16]]中x的[content[x]
打印(行)

?这似乎是一个常见的windows 10错误,我在控制台中打印时偶尔也会遇到。作为一种解决方法,您可以
尝试除了打印语句之外的
,直到它被修复…感谢您的回复,也许这就是问题所在,也是唯一的解决方案
['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