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 trialMarlon Card
16,394 PointsWe're not supposed to use 'open' as a python variable are we?
I'm doing the python Objects challenge and I have to assign 'open' as an attribute of a class. It pretty much fails because open is not specifically a reserved keyword but it conflicts. Am I correct?
class Store:
open = 8
close = 4
def hours(self):
return "We're open from {} to {}.".format(open, close)
3 Answers
Stone Preston
42,016 Pointsuse self.open and self.close. you need to refer to the open and close properties of an instance of the Store class
class Store:
open = 8
close = 4
def hours(self):
return "We're open from {} to {}.".format(self.open, self.close)
Kenneth Love
Treehouse Guest TeacherNothing is actually reserved in Python. I can create a variable with any name I want and, if it conflicts with a built-in, I just don't have access to that built-in anymore. The problem with your code, as Stone Preston pointed out, the problem with your code is that you didn't reference them with self.
since they belong to the instance.
Marlon Card
16,394 PointsYup, I see that, thanks for the help Stone and Kenneth!