简体   繁体   中英

How to extract keys from the json db with for loop

So i got custom database in python that looks like this

{"1":"0xAD488499b897a9667395526C39d0f3314A0f3FE9","2":"0xAD48843b897449667395526C39d0f3314A0f3FE9"}

And I want to extract only addresses I got other database that keeps count of how many addresses they are

db = DB("db/addrtouser.db")
db1 = DB("db/addrstorage.db")
db2 = DB("db/number.db")

    how = db2.get("how") # how many addreses they are

    checkaddr = #only second addreses
    for element in checkaddr:
        print('check')
        json = await tools.getonl(element)
        if json == False:
            author = int(db.get(element))
            owner = await client.fetch_user(author)  # your user ID
            await owner.send("YOUR NODE IS NOT ONLINE!")    

I want checkaddr to be "0xAD488499b897a9667395526C39d0f3314A0f3FE9","0xAD48843b897449667395526C39d0f3314A0f3FE9" So to just extract 2nds from the database with some while or for loop

To get all the values from a dictionary, do this:

my_dict = {"first_key": 1, "second_key": 2}
print(list(my_dict.values()))

This will print:

[1, 2]

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