I have found answers on stackoverflow that seem to be getting at my question, but I can't find something that I have been able to get to work. I have a really big list of strings like this:
db = ['a','b','c']
And I want to instantiate a class for each string, where unique strings would be the variable names:
a = MyClass()
b = MyClass()
c = MyClass()
I thought to convert the strings to variables, but this doesn't seem advisable from some answers I'm finding here on SO.
What is the best way of going about this?
dictionary?{'a':x, 'b':x, 'c':x}instances = dict((k, MyClass()) for k in db). Or a dict comprehension, if you're on at least 2.7:instances = {k: MyClass() for k in db}.