当我尝试在 Python 中打印所有 ASCII 字符时,只打印了 127 个字符,并且在 127 个字符之后出现输出错误。我无法理解该错误是什么意思。
例子:
t = list(range(0, 256))
for x in t:
print(str(x) + ". " + chr(x))
错误:
Traceback (most recent call last):
File "D:\Study\Pedia\Python Book\6. Functions\2. Built-in functions\ord_chr.py", line 6, in <module>
print(str(x) + ". " + str(chr(x)))
File "C:\Python33\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x80' in position 5: character maps to <undefined>
注意:我无法向您显示完整的输出,因为我无法从 sublime 输出控制台复制完整的原始输出。不知道它不能被复制的真正原因。
![在此处输入图像描述](https://i.stack.imgur.com/6Tsm7.png)