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

I am just not getting this.

I have been struggling with OOP for a while now. And this is no different. For the life of me I cannot figure this out. I don't believe I wrote this particular code correctly.

Is there anyone that can give me a thorough explanation on how this works?

morse.py
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, patternlist):
        return cls(PatternList)


class S(Letter):
    def __init__(self):
         pattern = ['.', '.', '.']
         super().__init__(pattern)

1 Answer

Steven Parker
Steven Parker
231,275 Points

You have a bit of work to do yet. The argument to the method won't be a pattern, but a string with some combination of the words "dash" and "dot" and hyphens. So this method will need to do essentially the opposite of what the "__str__" method does to convert that string into a pattern before returning the new instance.

Also note that your parameter is named "patternlist" (with lower-case "p") but you referenced "PatternList" (with capital "P") which is a different identifier.

thanks for the response Ill try this again and see if I can try to understand it.