I have been following the instructions from my "think python" book (the version for 3.x), and I have done everything that the book told me, but I still get a weird error in one of the exercises?
Here's the problem: I'm supposed to play around with the "TurtleWorld" from the module "swampy", and here's what I've got(this is exactly what is written in the book)
from TurtleWorld import *
world = TurtleWorld()
bob = Turtle
print (bob)
fd(bob, 100)
lt(bob)
fd(bob, 100)
wait_for_user()
when I try to run this code it should start up a new program called TurtleWorld, where you should see a turtle move east and then north, leaving two line segments behind, but when I try to run the program I get this error:
Traceback (most recent call last):
File "D:\Python34\Lib\swampy-2.1.5\Polygon.py", line 8, in <module>
fd(bob, 100)
File "D:\Python34\Lib\swampy-2.1.5\TurtleWorld.py", line 179, in fd
x, y = self.x, self.y
AttributeError: type object 'Turtle' has no attribute 'x'
This really weirds me out? I have, like I said, followed the book 100%.
By the way the book says this:
"The first line is a variation of the import statement we saw before; instead of creating a module object, it imports the functions from the module directly, so you can access them without using dot notation.
The next lines create a TurtleWorld assigned to world and a Turtle assigned to bob. Printing bob yields something like:
<TurtleWorld.Turtle object at 0x00FD1CD0>W
but when I use "print (bob)" I get this?
<class 'TurtleWorld.Turtle'>
I'll be happy to give any information you need to help me :)
Link to the online version of the book: http://faculty.stedwards.edu/mikek/python/thinkpython.pdf
page 47-48 is where this stuff is explained
Here's the link for the Swampy download: http://www.greenteapress.com/thinkpython/swampy/
I installed swampy by unzipping the "swampy" folder into the folder "libs", so the dir for the module looks like this now:
D:\Python34\Lib\swampy-2.1.5
Turtle
is a class where newTurtle
objects are made from.What you need is such a new object. You have to "call" the class to make a new object: