简体   繁体   English

如何读取打印语句并在循环中使用它们?

[英]how to read print statement and use them in loop?

code : 代码:

import re
import json
#open("sbins.txt","r")  
data = open("sbiiins.txt","r")
contents = data.read().strip()



for i, p in enumerate(re.findall(r'"password":[^"]*"(.*?)"', contents):

        print('{}="{}"'.format(i, p))

this code prints outputs this below strings by parsing a text file : 此代码通过解析文本文件将以下字符串输出此输出:

1="pass1425-*"
2="pass1234- "
3="pass0*++"
4="pass*-+"

i need to use these print statements and use them in loop 我需要使用这些打印语句并在循环中使用它们

for example : 例如 :

ids = (1,2,3,5,6,7,8)

for ind in ids:
     a= ids
      ....
       ....

In above code 在上面的代码中

1 should return pass1425-* 1应该返回pass1425- *

2 should return pass1234- 2应该返回pass1234-
... ...

As the comment said, use a dictionary. 如评论所述,使用字典。

https://www.w3schools.com/python/python_dictionaries.asp https://www.w3schools.com/python/python_dictionaries.asp

thisdict =  {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
thisdict["year"] = 2018

Your case: 您的情况:

thisdict =  {
    "1":"pass1425-*",
    "2":"pass1234- ",
    "3":"pass0*++",
    "4":"pass*-+"
}
print(thisdict["2"])

>>>>pass1234-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM