'int' Object Is Not Callable Error In Class
Solution 1:
You have both an instance variable and a method named increment
that seems to be your problem with that traceback at least.
in __init__
you define self.increment = 1
and that masks the method with the same name
To fix, just rename one of them (and if it's the variable name, make sure you change all the places that use it--like throughout the increment
method)
One way to see what's happening here is to use type
to investigate. For example:
>>> type(Zillion.increment)
<type'instancemethod'>
>>> z = Zillion('5')
>>> type(z.incremenet)
<type'int'>
Solution 2:
You have defined an instance variable in Zillion.__init__()
def__init__(self, digits):
self.new = []
self.count = 0self.increment = 1# Here!
Then you defined a method with the same name 'Zillion.increment()`:
defincrement(self):
[…]
So if you try to call your method like this:
big_number = Zillion()
big_number.increment()
.ìncrement
will be the integer you have defined in .__init__()
and not the method.
Solution 3:
Because you have a variable member self.increment
,and it has been set to the 1 in your __init__
function.
z.increment
represents the variable member which set to 1.
You can rename your function from increment
to the _increment
(or any other names), and it will works.
Post a Comment for "'int' Object Is Not Callable Error In Class"