"Andrew Martin" <amartin7...@gmail.com> wrote

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 *

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

OK, First things first. You have imported the file correctly.
Thats why you are getting the error.
Now read the error. It says there is a syntax error, which
there is. Can you see what you have done wrong in the
print statement. The little caret symbol is giving you
a big clue...

Finally, its considered bad style to use from foo import *
It can lerad to difficult to debug problems where two files
have things with the same name.
It is better to use

import foo

and then use foo.name to access things.
It is more typing but much safer and more reliable.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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

Reply via email to