python中open读取文件编码错误,怎么办??

比如你只需要提取文件中的手机号,而这些文件的编码都不相同,这时,可以这样:

f = open(filename,'r,encoding='utf-8',errors='ignore')

content = f.read()

#do something with content

f.close()