I have this weird problem i need help with. I have this code I want run in Spyder but I keep getting error stating
TypeError: 'int' object is not callable.
s ='abcdefgbobaaaaabob'
end = 3
bobs = 0
for i in range(len(s)):
finder = s[i:end]
if finder == 'bob':
bobs += 1
end += 1
print('Number of times bob occurs is: '+ str(bobs))
The weird part is that when I run the same code in IDLE, it works fine and gives the results I needed. I even tried running the code in pythontutor.com, no error.
Can someone please tell why this is happening!?
This error occurs when you have an object that is an integer number, but your code tries to use it as if it were a function. For example:
It doesn't look like the first of these is an issue here, so perhaps you have accidentally overridden one of the functions you are using?
>>> str(3)
'3'
>>> str = 17
>>> str(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
In Spyder you can check this in the Variable Explorer tab, and either right-click it and choose Remove
, or type (e.g.) del(str)
in the Python console to delete the incorrect assignment.