[Tutor] function error

Evert Rol evert.rol at gmail.com
Wed Sep 29 21:53:14 CEST 2010


>> Perhaps if you provide the full traceback from the error (assuming you're still getting this >error); tracebacks generally show the offending code as well. It may be something that's >simply overlooked but shows in the traceback.
>> 
>> 
> 
> here it is:
> 
> TypeError                                 Traceback (most recent call last)
> 
> ~/randomMove2.py in <module>()
> ----> 1
>      2
>      3
>      4
>      5
> 
> ~/randomMove2.py in randomMove2(d1, d2, a1, a2)
>      6          while 1:
>      7                  turtle.left(random.uniform(a1,a2))
> ----> 8                  checkForward.checkForward(random.uniform(d1,d2))
>      9                  if forward_failed == 'true':
>     10                          turtle.right(180)
> 
> ~/checkForward.py in checkForward(distance)
>      8
>      9         turtle.forward(distance)
> ---> 10         forward_failed = outOfBounds()
>     11         turtle.setx(old_position[0]); turtle.sety(old_position[1])
>     12         turtle._pen.down()
> 
> ~/checkForward.py in out_of_bounds()
>     19
>     20 def outOfBounds():
> ---> 21         if (abs(turtle.position()[0]) >
> turtle.window_height()/2) or (abs(turtle.position()[1]) >
> turtle.window_width()/2):
>     22                 return "true"
>     23         else:
> 
> TypeError: 'function' object is unsubscriptable


The only thing that strikes me as a bit odd, is that the last bit if given as '~/checkForward.py in out_of_bounds()', while the actual function seems to be called outOfBounds(). I don't know this traceback (ie, I can't tell what Python environment/editor you're using), but that could suggest the byte-compiled code you are running doesn't match with the actual current code. 
So you may have changed the function name in the meantime, *as well as* fixed a parenthesis in the process. But perhaps you haven't then recompiled your current code, and for some reason your Python executable hasn't picked up the most recent source code and recompiled that for you. 
If this is the case, it may be dependent on your development environment that does this (somewhat incorrectly, assuming you have at least saved the source file), but as I mentioned, I have no idea what you're using.

Then again, this is still a guess. But it's the only thing I can see that stands out.

Cheers,

  Evert



More information about the Tutor mailing list