UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

用python3:

Traceback (most recent call last): File "genetic_disease_filtrater.py", line 139, in intron = txt2.readlines()

  File "/usr/local/lib/python3.6/codecs.py", line 321, in decode

    (result, consumed) = self._buffer_decode(data, self.errors, final)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

找了半天原因,发现是被打开文件之前写出时:encoding = "utf-16"

解决办法:

打开文件时修改一下默认值:

with open(args.whanno_txt,"r",encoding='utf-16')

解决了

总结:

de这个bug跨时2天~  之前也在打开时“r”改为“rb”,后面一系列有字符串的地方都要在前面加b,非常麻烦。所以先检查一下被打开的文件是不是有什么问题,可能写出这个文件的时候就不是默认的'utf-8'。

你可能感兴趣的:(UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte)