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

@classmethod error

My code from the "Construction Zone" challenge:

```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):
    convert_string = string.split('-')
    output = []
    for i in convert_string = string.split('-')
        if i == 'dash':
            output.append('_')
        elif i == 'dot':
            output.append('.')
    return cls(output)

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

The code passed, but after copy/pasting all of this into my console, and then trying to test the from_string method, I got the following:

ns = from_string(Letter, 'dash-dot-dash-dash-dot') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'classmethod' object is not callable

So, the classmethod is defined and so is the Letter parent class. Am I not calling it correctly?
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)


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

2 Answers

Andrew Shannon
Andrew Shannon
9,115 Points

Take a look at your for loop. There is an error that I corrected :)

EDIT: I also dont understand the markdown on this page. Not sure why my code block is in white

    def from_string(cls, string):
        convert_string = string.split('-')
        output = []
        for i in convert_string:
            if i == 'dash':
                output.append('_')
            elif i == 'dot':
                output.append('.')
        return cls(output)

Ok I completely messed up the markdown in that last one. Gonna try again in a new window.