unbound method must be called with class instance 1st argument ??

Eric Renouf erenouf at opticominc.com
Mon May 21 21:53:18 EDT 2001


Dr Mike Lance wrote:
> 
> 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)


I think you need 
>>> b = Bags.Bag()


> 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

-- 
Eric Renouf
Software Engineer
Opticom Inc.
www.getiview.com



More information about the Python-list mailing list