Q:

Printing class variables with a for loop

I realize there are a million other ways to resolve this, so I'm not so much interested in alternative solutions, but more why this doesn't work.
class Car(object):

    condition = 'new'

    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg = mpg

my_car = Car('DeLorean', 'silver', 88)
for x in [condition, model, color, mpg]:
    print my_car.x

I'm trying to get it to print my_car.condition, my_car.model, my_car.color, and my_car.mpg.

A:

Your current code is just looking for the x attribute on a Car, which doesn't exist. You need to do dynamic attribute lookup with getattr. First off, though, your list of attributes should contain the appropriate names as strings, so that's:
for x in ['condition', 'model', 'color', 'mpg']:
    print(getattr(my_car, x))

