Your approach is ok, but I have just one mention (this is based on personal preferences): I'd iterate over a class not a list which is defined outside it. You'll just have to define a metaclass which supports iteration.
class IterPerson(type):
def __iter__(cls):
return iter(cls._allPeople)
class Person(metaclass=IterPerson):
_allPeople = []
def __init__(self, name, age, height):
self._allPeople.append(self)
self.name = name
self.age = age
self.height = height
if __name__ == '__main__':
Jeff = Person("Jeff", 20, "1.6")
Bob = Person("Bob", 39, "1.4")
Helen = Person("Helen", 19, "1.3")
for person in Person:
print(person.name + " is " + str(person.age))
Magic methods are always looked up on the class, so adding __iter__ to the class won't make it iterable. However the class is an instance of its metaclass, so that is the correct place to define the __init__ method.
Please note that I also put a _ in front of your list. This is how we tell python the list we'll create is private. I have also used if __name__ == "main": which is good practice (it is used to execute some code only if the file was run directly, and not imported)
Second, keep this kind of thing as simple as possible. Don't waste a lot of time and energy on something complex. This is a simple problem, keep the code as simple as possible to get the job done.