I'm new to Python and I've searched for an answer but can't find one. Maybe I'm just asking it the wrong way...
As an example, if I have a class as follows:
class Person(object):
def __init__(self, name):
self.name = name
I create a couple instances as follows and can get their attributes like this:
person1 = Person("John")
person2 = Person("Mike")
print person1.name
print person2.name
What I want to do is substitute "personX" with a variable, and this is the part I haven't figured out yet. I'd like to to use this to iterate through a list of names that map to class instances and get/set their attributes.
name1 = "person1"
print "%s".name % (name1) <--- this fails with "AttributeError: 'str' object has no attribute 'name'