Reffering to member Variables are annoying me


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

```python LOoks like I havent created a car object named my_car??????HELP class Car(object): condition = "new" my_car = Car(DeLorean, silver, 88)

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

<do not remove the three backticks above>

#2

@kevgro81,

class Car(object):
    condition = "new"

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

#Class definition has ended

# create an Instance of this Car class
my_car = Car("DeLorean", "silver", 88)
print dir(my_car)
print "=================="
print my_car.__dict__
print "=================="
print my_car.condition
print my_car.model
print my_car.color
print my_car.mpg

gives an output

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'color', 'condition', 'model', 'mpg']
==================
{'color': 'silver', 'mpg': 88, 'model': 'DeLorean'}
==================
new
DeLorean
silver
88

#3

Thanks for your input but it didnt work. Also I’m not quite sure why I would I implement a dict


#4

@kevgro81,
Just use the following

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

The rest was just to show you how you can display the Instance
so you can check on wether you really created an Object…or in Python called a dictionary

If you look in your Original Post,
you should should see that you made the
error of not using the right indentation


#5

Thanks for al of your support. The problem was I didnt make the inputs strings… terrible
Code and Learn I guess
I really appreciate the help