读文件:

读取文件
f = open('\info.txt')
fil = f.read()
f.close()

 按行读文件:

f = open("info.txt")
while 1:
   line = f.readline()
   line=line.strip('\n') # 去掉换行符
   if not line:
       break
   print line      
f.close() 

 

读取文件报错:

f1=open("fenci_result.txt",'r')

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 2892: invalid continuation byte

解决办法:

import codecs f1=codecs.open("fenci_result.txt",'r',encoding = "ISO-8859-1")

 

 

相关文章:

  • 2022-12-23
  • 2021-11-12
  • 2021-06-15
  • 2021-08-16
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-01
  • 2021-11-25
  • 2022-12-23
  • 2022-01-01
  • 2021-08-23
  • 2022-12-23
相关资源
相似解决方案