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 trialAvery Uslaner
15,099 PointsNot sure I understand the error here. Gives me: Bummer! __init__() got an unexpected keyword argument 'first_name'
I think it would be helpful to know how the object is being created.
import re
string = '''Love, Kenneth: 20
Chalkley, Andrew: 25
McFarland, Dave: 10
Kesten, Joy: 22
Stewart Pinchback, Pinckney Benton: 18'''
players = re.search(r'''
^(?P<last_name>[\w\s]+),\s
(?P<first_name>[\w\s]+):\s
(?P<score>\d+)$
''', string, re.X|re.MULTILINE)
class Player(object):
def __init__(self, first, last, score):
self.last_name = last
self.first_name = first
self.score = sc
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsThe parameters of the __init__
need to match the group names from the players
search
class Player(object):
def __init__(self, first_name, last_name, score): #<-- fixed parameter names
self.last_name = last_name
self.first_name = first_name
self.score = score # < - fixed typo
Avery Uslaner
15,099 PointsAvery Uslaner
15,099 PointsSo the names of my parameters actually matters? I thought I could name them anything so long as I assigned them to the correctly named attributes.
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsIdeally, you can name the parameters anything you like, but since the order of the
__init__
parameters were not specified, the method will be called using keyword arguments (kwargs).In this challenge, the grader is using the output of
players
to createPlayer
instances and calling__init__
with keywords based on the group names from there.search
output. So the parameters much match the group names.James N
17,864 PointsJames N
17,864 Pointsthanks! this helped me, too!