pyhton newbie questions

having trouble running a python script.
i created some simple python scripts. and i can't seem to get them to run?
one file i called spam.py and i will list it's contents here.
[code]
print 2 ** 8
print 'the bright side ' + 'of life'
[code]

i stored the file in a directory in my home directory which i called python.
/users/jamescollins/python/spam.py

a book i am reading says
"once you've saved this text file, you can ask Python to run it by listing it's full filename as the first argument to a python command, typed at the shell prompt"
the output from the book after running the script is as follows:

[code]
% python spam.py
256
the bright side of life
[code]

in terminal i started Python
and then typed

[code]
python spam.py
[code]
i got the following error messages


[code]
python spam.py

File "<stdin>", line 1
python spam.py
^
SyntaxError: invalid syntax
[code]

just trying to run simple python scripts
any help would be appreciated.

one thing i did was go into terminal into my python directory, and typed
python spam.py
and the program ran in terminal
i think the book was telling me to run spam.py as an argument when i launched python?
how do i get the program to run in the interactive prompt?
i also used the import command to import a file which i called spam.py
here is the output from my terminal session

[code]
import spam.py

256
the bright side of life
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named py
[code]

does anyone know what this added text means?

[code]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named py
[code]
another thing i will add is that i have two versions of python on my computer.
one i think is python that came with the developer tools, which i run from terminal.
another is a version i downloaded from the internet.
the one i downloaded from the internet has text in different colors.
the one i run from terminal seems easier to open files because i can switch to the directory where i have my scripts, and then start python and run the scripts by importing them. i also can call up python with a file as an argument.
the one i downloaded from the internet is giving me error messages
like when i try to import spam.py i get the following

[code]
import spam.py


Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import spam.py
ImportError: No module named spam.py
[code]
how do i import a file?
do i need to give it a path?

again any help would be appreciated.

Posted on Apr 29, 2008 12:07 PM

Reply
5 replies

There are no replies.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

pyhton newbie questions

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.