python3.7 ‘utf-8‘ codec can‘t decode byte 0xbe in position 0: invalid start byte

报错代码:


  
   
   
  1. import sys
  2. path = r"..." #数据来源
  3. f = open(path)
  4. line = f.readline()
  5. while line: #提取数据
  6. a = line.split( )
  7. b = a[:]
  8. print(b)
  9. data.append(b)
  10. line = f.readline()
  11. f.close

报错信息:'utf-8' codec can't decode byte 0xbe in position 0: invalid start byte

修改代码:只在open()处修改


  
   
   
  1. import sys
  2. path = r"..." #数据来源
  3. f = open(path, encoding= 'gbk', mode= 'r')
  4. line = f.readline()
  5. while line: #提取数据
  6. a = line.split( )
  7. b = a[:]
  8. print(b)
  9. data.append(b)
  10. line = f.readline()
  11. f.close

猜你喜欢

转载自blog.csdn.net/weixin_44110913/article/details/109399612