On 12/06/2010 05:50, Andrew Martin wrote:
Hey, everyone, I am new to programming and just downloaded Python 2.6 onto
my windows vista laptop. I am attempting to follow 4.11 of the tutorial
called "How to Think Like a Computer Scientist: Learning with Python v2nd
Edition documentation" (
http://openbookproject.net/thinkcs/python/english2e/ch04.html). However, I
am having some trouble. First off, I do not understand how to import things
into the python shell. I have a script I saved as chap03.py, but when I try
to import it into the python shell i get an error like this:

from chap03 import *

This is generally considered bad practice, I'll let you do some research to find out why. :)


Traceback (most recent call last):
   File "<pyshell#8>", line 1, in<module>
     from chap03 import *
   File "C:/Python26\chap03.py", line 2
     print param param
                     ^
SyntaxError: invalid syntax


The chap03.py file is a simple one that looks like this:
def print_twice(param):
     print param param

One of the great advantages of Python is trying things from an interactive prompt, so let's go.

c:\Users\Mark\python>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def print_twice(param):
...     print param param
  File "<stdin>", line 2
    print param param
                    ^
SyntaxError: invalid syntax

So it is!  What's print_twice trying to do, let's guess?

>>> def print_twice(param):
...     print param, param
...
>>> print_twice('Hi Andrew')
Hi Andrew Hi Andrew
>>>

Better! See how I slotted that comma into the function print_twice, just hope my guess is right. So run up some editor/IDE and slap that comma in there, it should at least keep you going.


My second problem is that I need to install and import GASP in order to
follow the tutorial. When I tried to do import it, I ran into an error like
this:
from gasp import *

Traceback (most recent call last):
The line above basically says "start reading from the bottom up"
   File "<pyshell#9>", line 1, in<module>
     from gasp import *
   File "C:\Python26\lib\site-packages\gasp\__init__.py", line 1, in<module>
     from api import *
   File "C:\Python26\lib\site-packages\gasp\api.py", line 1, in<module>
     import backend
   File "C:\Python26\lib\site-packages\gasp\backend.py", line 7, in<module>
     except ImportError: raise 'Pygame is not installed. Please install it.'
TypeError: exceptions must be old-style classes or derived from
BaseException, not str
The TypeError means exactly what it says. The ImportError is trying to raise an exception, but what follows is a string type, not an exception type. Just install Pygame to get yourself going, at some point in the tutorial you're bound to run into exception handling.


Can anybody help me with this?

Thanks a lot

P.S. SORRY FOR THE LONG EMAIL

By some standards this doesn't even qualify as short, it's just a snippet.

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

HTH, and keep asking as Python lists are renowned for their friendlyness.

Mark Lawrence.


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to