[Tutor] Using Python in Windows
broek at cc.umanitoba.ca
broek at cc.umanitoba.ca
Wed Jun 25 10:35:46 CEST 2008
----- Message from ben at pacificu.edu ---------
Date: Tue, 24 Jun 2008 18:27:59 -0700
From: Ben <ben at pacificu.edu>
> Hi,
>
> I'm trying to learn Python in Windows XP. I've been going through the
> Python version of Allen Downey's open source textbook. I frequently
> find that the instructions he gives don't work for me when I try to
> run them in IDLE. For example, in Ch. 4 he says you should load up
> GASP (http://openbookproject.net//thinkCSpy/ch04.xhtml#auto10) and
> play around with it. Here's what happens when I try what he says to
> do:
>
> IDLE 1.2.2
>>>> from gasp import *
>
> Traceback (most recent call last):
> File "<pyshell#0>", line 1, in <module>
> from gasp import *
> ImportError: No module named gasp
>>>>
Hi Ben,
gasp isn't part of python; it is a module specific to the book you are
reading. There should be a link somewhere on the book's site from
which you can dowload it.
> When I try to put all the information in a module, save it, and run
> it, I get "there's an error in your program: invalid syntax", and it
> highlights instance. Below is what my module looks like.
>
> from gasp import *
> begin_graphics()
> Circle((200, 200), 60)
> Circle instance at (200, 200) with radius 60
> Line((100, 400), (580, 200))
> Line instance from (100, 400) to (590, 250)
> Box((400, 350), 120, 100)
> Box instance at (400, 350) with width 120 and height 100
> end_graphics()
If you look at the page again, you will see that the relevant text looks like:
>>> from gasp import *
>>> begin_graphics()
>>> Circle((200, 200), 60)
Circle instance at (200, 200) with radius 60
>>> Line((100, 400), (580, 200))
Line instance from (100, 400) to (590, 250)
>>> Box((400, 350), 120, 100)
Box instance at (400, 350) with width 120 and height 100
>>> end_graphics()
>>>
The `>>>' are the prompts for the interactive interpreter[*] and the
lines without them are the results of running the commands typed at
the prompts. So, if you want to put it into a module, you will have to
include only the `>>>' lines (don't include the `>>>'s themselves,
though.
[*] Do you know what I mean by `interactive interpreter'?
Trying to run that will take you back to your first problem. So, see
if you can find a download link for the module on the book's site, and
give it another go. Report back if still stymied.
Best,
Brian vdB
More information about the Tutor
mailing list