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 __init__

Tara Edwards
Tara Edwards
6,521 Points

Of course Task 1 is no longer passing, now do I keep that task while using keyword arguments?

I feel like I am assigning the value of name twice. If I keep it to the init arguments, Task 1 no longer passes. If I keep task 1, I get error messages. Am I missing something? Commenting out the original assignment does not work.

student.py
class Student:
  name = "Tara" 

  def __init__(self, **kwargs):
    self.name = kwargs.get(name, "Tara") 

2 Answers

The argument you pass to kwargs.get() should just be the key of the dictionary entry that you want to extract.

Tara Edwards
Tara Edwards
6,521 Points

Well, I made some changes. Thing is, the instructions said "override the init". Do I declare init twice? If so, why does it make Task 1 not work?

class Student:
    def __init__(self):
        self.name = 'Tara'

    def __init__(self, **kwargs):
        self.name = kwargs.get(name, "Joe")
Tara Edwards
Tara Edwards
6,521 Points

OK, I have looked at other posts on the same subject (I guess I had better luck looking for init than anything else).

class Student: 
    name = 'Tara' 
    def __init__(name='Joe'): 
        self.name = name