Welcome to the Treehouse Community
Looking to learn something new?
Nicolae Laurentiu1,538 Points
Hy, I don't understand why the code doesn't run
class Fruit: test = "test" class Orange(Fruit): has_pulp = True def squeeze(self): return has_pulp print(Orange().squeeze())
[MOD: added ```python formatting -cf]
Chris FreemanTreehouse Moderator 67,986 Points
The error in running your code is:
Traceback (most recent call last): File “<string>”, line 12, in <module> File “<string>”, line 9, in squeeze NameError: global name ‘has_pulp’ is not defined
To reference the 'has_pulp' attribute of a class
instance, the instance needs to be referenced. The parameter
self is used to point to the current instance. Using
self.has_pulp will fix the error.
Post back if you need more help. Good luck!!!
I'm very interested in how this works. I'm normally used to doing OOP like so:
mandarin_orange = Orange() mandarin_orange.squeeze()
I didn't know it was even possible to do
Orange().squeeze() (of course, if the
self.has_pulp attribute were correctly implemented). Would you call this a method call directly on the class, rather than an instantiated object's method call (as would be
feeling kinda confused but kind of learning