Here’s a Python gotcha that got me. Here is my function to print out a range of sinusoidal values:
import math
def cycle(centre, range):
theta = 4.71
speed = 0.1
for i in range(0,80):
theta = theta + speed
value = centre + (range * math.sin(theta))
print value
I got the following error which confused the hell out of me:
Traceback (most recent call last):
File "cycle2.py", line 11, in
cycle(0.0,10.0)
File "cycle2.py", line 6, in cycle
for i in range(0,80):
TypeError: 'float' object is not callable
Can you see it? It took me a while. I’d assigned a variable called range and then tried to call the range() function. I’d overloaded a built-in function. Duh!
I just had to rename my variable and it was good.