Calling a class method

Steven D'Aprano steve at
Sat Apr 17 10:16:17 EDT 2010

On Sat, 17 Apr 2010 15:44:56 +0200, Andreas Waldenburger wrote:

> On Sat, 17 Apr 2010 06:09:21 -0700 (PDT) vsoler
> <vicente.soler at> wrote:
>> I got the following error:
>> TypeError: unbound method duplica() must be called with TTT instance as
>> first argument (got int instance instead)
>> What am I doing wrong?
> Not reading the error message.
> You need to create a TTT instance and call your method from that:
> inst = TTT()
> inst.duplica(7)

He already has a TTT instance. Since he's calling the TTT.duplica method 
from another TTT method, the easiest way (and the most Pythonic, and the 
most sensible, is to do this:


Calling duplica from the class as TTT.duplica will work, if he does:

TTT.duplica(self, 7)

but why would you want to?


More information about the Python-list mailing list