Python Turtle AttributeError: 'Turtle' object has no attribute 'position'

1k Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

You may be mixing up the turtle module with swampy.TurtleWorld's Turtle class.

In the turtle module, there is indeed a position() method, however there isn't in swampy.TurtleWorld's Turtle class, as mentioned by @Georgy in the comments.

You can instead use bob.get_x() and bob.get_y() for its x, y coordinates.