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

André Nårstad
André Nårstad
2,951 Points

Teacher's note

I tried the code from the teacher's note. But when running the code I got an AttributeError: 'NewClass' object ha no attribute 'name'

Wondered if the code in the method:

def name_method(self):
       return self.name

should be:

def name_method(self):
       return self.name_method

Any comment on this?

[MOD: added ```python formatting -cf]

Can you provide link to the page with the note?

André Nårstad
André Nårstad
2,951 Points

It from "Object-Oriented Python" > "Instant Objects" > "What Are Objects And Classes?"

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Can you please provide your complete code you’re trying to run?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You are correct!!. The teacher’s notes for What are Objects and Classes lists the code:

class NewClass:
    name_attribute = "Kenneth"

    def name_method(self):
        return self.name

The method should be referencing self.name_attribute and not self.name

Good catch!!