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 trialMike Brooks
3,389 PointsDo not understand the question.
In the final challenge of Python Regular expressions, the challenge says: "Wow! OK, now, create a class named Player that has those same three attributes, last_name, first_name, and score. I should be able to set them through init." Since we were doing regular expressions, I created a init(self, inTxt) method and used a regular expression to translate the inTxt into the three variables. When I tested in pyCharm it worked. When in ran it in the challenge window; it told me there was an unexpected "score" parameter????
import re
string = '''Love, Kenneth: 20
Chalkley, Andrew: 25
McFarland, Dave: 10
Kesten, Joy: 22
Stewart Pinchback, Pinckney Benton: 18'''
players = re.match(r'''
(?P<last_name>^[-\w ]*)
[, ]{2}
(?P<first_name>[-\w ]*)
[: ]{2}
(?P<score>\d{1,3})$
''', string, re.X | re.M)
class Player():
last_name = ""
first_name = ""
score = ""
def __init__(self, inTxt):
xxx = re.match(r'''
(?P<last_name>^[-\w ]*)
[, ]{2}
(?P<first_name>[-\w ]*)
[: ]{2}
(?P<score>\d{1,3})$
''', inTxt, re.X | re.M)
self.last_name = xxx.group("last_name")
self.first_name = xxx.group("first_name")
self.score = xxx.group("score")
1 Answer
Mike Brooks
3,389 PointsThanks very much. It will be the best answer as soon as I can figure out how to make it so.
Mike Brooks
3,389 PointsSee previous comment by Francesco Cabiddu. It is the best answer.
Francesco Cabiddu
2,297 PointsFrancesco Cabiddu
2,297 PointsHi mike! I had the same problem. I think that the solution is easier, because the challenge ask you to create a class that allows someone to add some specific arguments to it. In this sense if I define a general class like this:
than you will be able to define its arguments doing for example:
player = Player(**players.groupdict())