for循环之列表解析:

def get_webinfo(path):
web_info = {}
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:05  干it的小张  阅读(390)  评论(0编辑  收藏  举报