Calling a class method
vsoler
vicente.soler at gmail.com
Sat Apr 17 09:09:21 EDT 2010
I have the following script:
class TTT(object):
def duplica(self):
self.data *= 2
def __init__(self, data):
self.data = data
TTT.duplica(self.data)
def __str__(self):
return str(self.data)
print
obj=TTT(7)
print obj
And I want 14 printed (twice 7)
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?
More information about the Python-list
mailing list