使用codecs的utf-8编码打开文件:

#导入codecs模块:
import codecs
def get_webinfo(path):
web_info = {}
config = codecs.open(path,"r","utf-8")
# with open(path,"r",encoding="utf-8") as config:
for line in config:
#使用列表解析:
result = [ele.strip() for ele in line.split("=")]
web_info.update(dict([result]))
return web_info
if __name__ == '__main__':
info = get_webinfo(r"C:\我的代码\selenium自动化测试\百度云登录\webinfo")
for key in info:
print(key,info[key])

你可能感兴趣的:(使用codecs的utf-8编码打开文件:)