[Tutor] Problems with Importing into the Python Shell

Alan Gauld alan.gauld at btinternet.com
Sat Jun 12 22:17:37 CEST 2010

"Andrew Martin" <amartin7211 at 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.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list