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.
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:
% python spam.py
256
the bright side of life
in terminal i started Python
and then typed
i got the following error messages
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
does anyone know what this added text means?
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
how do i import a file?
do i need to give it a path?
again any help would be appreciated.
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'
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:
% python spam.py
256
the bright side of life
in terminal i started Python
and then typed
Code:
python spam.py
i got the following error messages
Code:
>>> python spam.py
File "<stdin>", line 1
python spam.py
^
SyntaxError: invalid syntax
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
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
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
do i need to give it a path?
again any help would be appreciated.