I need to create a new instance of a specific class named from the content of a variable.
For example create an instance of the Foo class named whatever the content of the "s" variable is. This is what I tried
class Foo:
pass
s = 'bar'
eval(s) = Foo
The above code returns a "can't assign to function call" error.
I need it to create an instance called 'bar' in the Foo class in this case but I also need to be able to change the 's' variable to any string and for it to still work.
If there is another way for me to create class instances and then access them later with the "s" variable that would work too.
A lot of similar questions have been answered by creating pre defined dictionaries but in my case these dictionaries would have to be several hundred items long and hand written, and so are impractical and not very pythonian. I need to create and access the instance completely dynamically, hopefully by name but if there is another way I'm open to that too.