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
mourad marzouk
5,560 PointsWorked 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?
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)
1 Answer
mourad marzouk
5,560 PointsHey 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.
Dave StSomeWhere
19,870 PointsDave StSomeWhere
19,870 PointsHow did it work when
patternis not declared in your__str__function?Also, I would avoid declaring a variable named
strsince it is a built-in variable name. Also, it is just not needed.