I have the following code to play with turtle within turtleworld
:
>>> from swampy.TurtleWorld import *
>>> world = TurtleWorld()
>>> bob = Turtle()
>>> fd(bob, 100)
>>> bob.position()
>>> bob.reset()
There is no issue with executing the fd(bob, 100)
line but when I try to check turtle position it returns AttributeError
:
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
bob.position()
AttributeError: 'Turtle' object has no attribute 'position'
Why is this happening? What am I missing? I have read the documentation and it states that both position()
and reset()
methods should be available.
You may be mixing up the
turtle
module withswampy.TurtleWorld
'sTurtle
class.In the
turtle
module, there is indeed aposition()
method, however there isn't inswampy.TurtleWorld
'sTurtle
class, as mentioned by @Georgy in the comments.You can instead use
bob.get_x()
andbob.get_y()
for its x, y coordinates.