2

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.

Y2H
  • 2,419
  • 1
  • 19
  • 37
halny
  • 63
  • 6
  • 1
    I'm not familiar with this library, but it looks like there is no such attribute indeed: https://github.com/AllenDowney/Swampy/blob/master/python3/TurtleWorld.py#L102 – Georgy May 06 '18 at 11:38
  • Thank you. As stated below by HKJeffer I have mixed `turtle` module with `swampy.TurtleWorld`'s `Turtle` class. Thank you for the link, I need to read it. – halny May 06 '18 at 12:10

1 Answers1

1

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.

HKJeffer
  • 209
  • 2
  • 11
  • Thank you, I just got lost at the beginning of my adventure with Python. It seems too many turtles around ;) – halny May 06 '18 at 12:12