使用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])
posted @ 2019-12-22 20:11  干it的小张  阅读(776)  评论(0编辑  收藏  举报