3
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
3
  • Possible duplicate? Commented Apr 6, 2018 at 7:51
  • It seems to be a common windows 10 bug, I have it also occasionally on printing in the console. As a workaround you could try except around the print statement until it's fixed... Commented May 16, 2018 at 9:00
  • thanks for your reply, maybe that's the problem and the only solution Commented May 22, 2018 at 23:27

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Another answer:

I also met same problem in Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)]

I ran into this issue When I want to process some text which contains Chinese Character.

the core code is:

content = fp.read().strip().strip("\n").split("\n")  # fp is an opened file obj
line = "".join([content[x] for x in [1, 4, 7, 10, 13, 16]])
print(line)

the right way is: using unicode instead of str(utf-8) before iter it

content = fp.read().strip().strip("\n").decode("utf-8").split("\n") # fp is an opened file obj
line = "".join([content[x] for x in [1, 4, 7, 10, 13, 16]])
print(line)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.