unbound method must be called with class instance 1st argument ??
scarblac at pino.selwerd.nl
Tue May 15 03:24:06 EDT 2001
Dr Mike Lance <LanceM at netaccess.co.nz> wrote in comp.lang.python:
> 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?
You forgot the () needed to make an instance out of the class, the second
line should have been
b = Bags.Bag()
As it was b was just a new name for the class, and you can't call methods
directly on the class.
More information about the Python-list