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
Daniel Maisano
7,449 PointsLet's practice using @classmethod! help please
I tried looking at all the other answers but still can't see what I'm doing wrong - probably something really simple.
Here's the code challenge: Let's practice using @classmethod!
Create a class method in Letter named from_string that takes a string like "dash-dot" and creates an instance with the correct pattern (['_', '.']).
Here is my code:
@classmethod
def from_string(cls, string1):
final_string = []
text = string1.split("-")
for i in text:
if i == "dash":
final_string.append("_")
elif i == "dot":
final_string.append(".")
return cls(final_string)
1 Answer
Scott Bailey
13,190 PointsI put your code into the challenge and it passed first time - try refreshing the page and if needed copy and paste in your code again, sometimes I have this issue (must be something with the server).
Good work!
Daniel Maisano
7,449 PointsDaniel Maisano
7,449 PointsYep that worked, thanks! Now I know