Hi guys, it's been a while since I posted and I've learned a lot since then. 
Today I have a question on classes, I can't get mine to work.
class alist(list):
 def __init__(self, b, a):
 self = list()
 self.append(b)
 a = a + b
 def appendit(self):
 self.append(a)
 
print(alist(2,4))
[]
#It's blank!
c = alist(2,4)
c.appendit()
print(c)
[[...]]
#It's still blank!
If I add this:
 a = a + b
 
the last line of my deffinition I get:
c = alist(2,4)
c.appendit()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 7, in appendit
UnboundLocalError: local variable 'a' referenced before assignment
If I make a nonlocal I get
SyntaxError: name 'a' is parameter and nonlocal
I want it to get my list and all the members in it when printing for instance. 
I also would like to without making them global create two variables which I 
can use throughout the whole class as their value will not change.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to