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])
原文地址:https://www.cnblogs.com/zhang-da/p/12080841.html