环境:python2.7
代码示例:
with open('1.txt','r',encoding='utf-8') as f: lines = f.readlines() for line in lines: line =line.strip()
使用with open() as f 语句提示错误:
TypeError: 'encoding' is an invalid keyword argument for this function
解决办法:
import io with io.open('1.txt','r',encoding='utf-8') as f: lines = f.readlines() for line in lines: line =line.strip()