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

mourad marzouk
mourad marzouk
5,560 Points

Worked in work spaces...

I tested this in workspaces with an instance call and it worked. However didnt worked in here, has something to do with that S class?

morse.py
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern

    def __str__(self):
        str=""
        for x in range(len(pattern)):
            if pattern[x] is '.':
                pattern[x]='dot'
            elif pattern[x] is '_':
                pattern[x]='dash'
        str='-'.join(pattern)        
        return str

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

How did it work when pattern is not declared in your __str__ function?

Also, I would avoid declaring a variable named str since it is a built-in variable name. Also, it is just not needed.

1 Answer

mourad marzouk
mourad marzouk
5,560 Points

Hey Dave,

I think I know where I messed this up, please correct me if I'm wrong.

but in workspaces I was calling to the class in an instance completely out of the class. I was passing a pattern through and running it like a function. I wasn't using the class S to pass the pattern. I declared the self and make it create/append rather then rewrite the existing pattern list and it worked.