Reffering to member variables help


Referring to member variables

Traceback (most recent call last):
File "python", line 1, in
File "python", line 3, in Car
NameError: name 'Car' is not defined

I expect it to print the values listed for my_car

class Car(object):
    condition = "new"
    my_car = Car("supra", "blue", "20")

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

    print my_car.condition
    print my_car.model
    print my_car.color
    print my_car.mpg


isn't Car defined on line 3?


No, it's part of Car's definition
(And why would a Car be part of Car's definition?)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.