具有将以下内容输出到txt文件的python代码:
out.txt包含:
"1":"pass1425-*",
"2":"pass1234- ",
"3":"pass0*++",
........
.....
"100":"pass*-+"
需要将此1,2,3,4,5,6,... 100的值用于循环功能
ids = (1,2,3,5,6,7,8.....)
for ind in ids:
a= ids
....
....
1应该返回pass1425- *
2应该返回pass1234-
在提到id的循环中 ... ...
答案 0 :(得分:0)
我从您的问题中了解了什么
我在下面写了代码
f = open("out.txt","r")
dictres = {}
for line in f:
try:
val = line.split(":")
dictres[int(val[0].replace('"',""))] = val[1].replace('"',"").replace(",","").replace("\n","")
except Exception as e:
print("Data in line is not enough to format")
ids = (1,2,3)
for id in ids :
try:
print(dictres[1])
except:
print(str(id)+"id not found ")