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 (retired) Objects Create a Class with a Method

Van Sanders
Van Sanders
16,087 Points

Problem with Workspace?

I can't tell why this won't pass...

I do notice that 'open' isn't colored like 'close' is, leading me to suspect that 'open' is a python keyword that might be screwing with this challenge?

Thanks in advance for any help!

method.py
class Store:
  open = 9
  close = 4

  def hours(self):
    return "We're open from {} to {}.".format(open, close)

3 Answers

John Hill
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
John Hill
Front End Web Development Techdegree Graduate 35,236 Points

Hey hey, you're correct that open() is a keyword in python. It's a built-in function -- check it here -- but that won't interfere with the challenge.

Looks like you've called self in the hours function, so wouldn't you also call self on open and close in the format function? i.e., self.open and self.close? Perhaps??

John Hill
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
John Hill
Front End Web Development Techdegree Graduate 35,236 Points

No problem man! Yeah, I had to spend an evening wrapping my head around using self properly. I like the way you're thinking about it though; if it were that way, it'd clean up a lot of extra self-s in the code. I found this stackoverflow to be handy in understanding self, particularly the answer with the arrows.

Van Sanders
Van Sanders
16,087 Points

Oh man... I thought that once 'self' was passed into the method, the rest of the code within that method would know where to look.

Thanks so much!