unbound method must be called with class instance 1st argument ??
Dr Mike Lance
LanceM at netaccess.co.nz
Tue May 15 03:20:20 EDT 2001
I was trying out the following example from the tutorial...
class Bag:
def __init__(self):
self.data = []
def add(self, x):
self.data.append(x)
def addtwice(self, x):
self.add(x)
self.add(x)
I stored this in bags.py and then tried the following...
>>> import Bags
>>> b = Bags.Bag
>>> b.add(1)
This last line resulted in an error message which was...
Traceback (innermost last):
File "<interactive input>", line 1, in ?
TypeError: unbound method must be called with class instance 1st argument
>>>
It looks like the instance attribute data does not exist?
What is the cause of this problem and what is the solution?
TIA
More information about the Python-list
mailing list