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 trialamypa
1,473 PointsError in @classmethod (https://teamtreehouse.com/library/objectoriented-python-2/advanced-objects/construction-zone)
I'm not sure what is wrong with my code. When I tried to run the same script in the workspace:
b = Letter.from_string('dash-dot-dash') b.pattern
it returned:
['-', '.' , '-' ]
which seemed to be the right answer....
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __iter__(self):
yield from self.pattern
def __str__(self):
output = []
for blip in self:
if blip == '.':
output.append('dot')
else:
output.append('dash')
return '-'.join(output)
@classmethod
def from_string(cls, string):
string_list = string.split('-')
new_list = []
for blip in string_list:
if blip.lower() == 'dot':
new_list.append('.')
elif blip.lower() == 'dash':
new_list.append('-')
else:
pass
return cls(new_list)
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)