小编pbe*_*r13的帖子

Python UnicodeDecodeError

我正在编写一个Python程序来读取输出到文本文档中的DOS树命令.当我到达循环的第533次迭代时,Eclipse会给出错误:

Traceback (most recent call last):
  File "E:\Peter\Documents\Eclipse Workspace\MusicManagement\InputTest.py", line 24, in  <module>
    input = myfile.readline()
  File "C:\Python33\lib\encodings\cp1252.py", line 23, in decode
   return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 3551: character maps  to undefined
Run Code Online (Sandbox Code Playgroud)

我已阅读其他帖子,并将编码设置为latin-1无法解决此问题,因为它返回UnicodeDecodeError另一个字符,并且尝试使用utf-8也是如此.

以下是代码:

import os
from Album import *

os.system("tree F:\\Music > tree.txt")

myfile = open('tree.txt')
myfile.readline()
myfile.readline()
myfile.readline()

albums = []
x = 0

while x < 533:
    if not input: break
    input = myfile.readline()
    if len(input) < 14:
        artist …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

7
推荐指数
1
解决办法
5861
查看次数

标签 统计

python ×1

python-3.x ×1