python - How do I create a variable number of variables? -


how accomplish variable variables in python?

here elaborative manual entry, instance: variable variables

i have heard bad idea in general though, , security hole in python. true?

use dictionaries accomplish this. dictionaries stores of keys , values.

>>> dct = {'x': 1, 'y': 2, 'z': 3} >>> dct {'y': 2, 'x': 1, 'z': 3} >>> dct["y"] 2 

you can use variable key names achieve effect of variable variables without security risk.

>>> x = "spam" >>> z = {x: "eggs"} >>> z["spam"] 'eggs' 

make sense?


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -