简体   繁体   中英

Python: How do you use a variable value in a Dict Call?

I'm trying to use a variable to set the Dict path for another variable:

podtype = "podcast1" #this changes based on what you select in the UI

client_config = {
podcast1: {
name: "test"
}
podcast2: {
name: "test"
}
}

podConif = client_config.podtype['name']  #I need the value of **podtype** in this code to dynamically select what part of the dict tree to grab.

Any ideas? I assume I need to wrap it in something like a get() wrapper?

Thanks guys, it was due to my mixing up JS object syntax and Py dicts.

This worked:

podConif = client_config[podtype]['name']

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