简体   繁体   中英

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-*

2 should return pass1234-
...

As the comment said, use a dictionary.

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-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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