Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Instant Objects Master Class

Kimmo Ojala
seal-mask
.a{fill-rule:evenodd;}techdegree
Kimmo Ojala
Python Web Development Techdegree Student 8,257 Points

Calling a dictionary

In workspace I get an error message that the dictionary object is not callable. Don't really know why?

racecar.py
class RaceCar:
    color = None
    fuel_remaining = None

    def __init__(self, color, fuel_remaining, **kwargs):
        self.color = None
        self.fuel_remaining = None
        for key, value in kwargs.items():
            setattr(self, key, value)

2 Answers

Josh Keenan
Josh Keenan
20,315 Points
class RaceCar:
    def __init__(self, color, fuel_remaining, **kwargs):
        self.color = color
        self.fuel_remaining = fuel_remaining
        for key, value in kwargs.items():
            setattr(self, key, value)

You just had a few mistakes in there, you don't need to define (and shouldn't define) the color outside of init if you are already doing it in there, it's purpose is to initialise those variables.

Next you don't set the value in init, you just take the arguments you are passing in and use them, hope this makes sense!