Python – Is there a way to create objects in a similar way that setattr works?

I have a list and I want every item to be created into an object with the name from the list. eg.

list = [Paul, Jess, Craig...]
class Person():
    pass
Paul = Person()
Jess = Person()
Craig = Person()

Any way to do this quickly as my list is very long?



Read more here: https://stackoverflow.com/questions/64397854/python-is-there-a-way-to-create-objects-in-a-similar-way-that-setattr-works

Content Attribution

This content was originally published by Elena at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: