我有Input.txt
,此文件的内容是:
Name1=Value1
Name2=Value2
Name3=Value3
所需的输出:获取key==Name1
的值。
条件:这需要由Python中的Dictionary实现。
with open("Input.txt", "r") as param_file:
text = param_file.readlines()
d = dict(x.strip().split("=") for x in text)
for k, v in d.items():
if k == "Name1":
print(f"{d[k]}")