I am running Python 2.6.2 on my windows 7 RC 1 x64 laptop and attempting to
learn python as a beginner programmer on my own, but I'm having difficulty
getting python to run the .py files I create through the IDLE shell and from the
command prompt using the commands from the book located at
http://www.openbookproject.net/thinkcs/python/english2e/index.xhtml
I'd like to be able to call files within python programs and it seems that
whenever I list the path to a folder on my computer - I only get errors:
the book tells me that to call a python program you have to type
"$ python firstprogram.py"
This doesn't work on my computer from within idle, or from the command line...
I'm obviously doing something wrong, but maybe the book could be made to clarify
this?
For example - I'm trying to call the program I wrote - madlib.py, stored at
(C:\Users\Shawn\Documents\Pydoc\madlib.py)
I tried in multiple ways. I can only run files using the idle file menu or the
windows file system point and click way... Maybe the book could be more clear
for beginners like myself in this particular section, because I would like to
delve into learning to program in python... but I can't get the files I'm
writing to run properly:
Here is a subset of my various attempts separated by blank lines
>>> $ python madlib.py
SyntaxError: invalid syntax
>>> madlib.py
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
madlib.py
NameError: name 'madlib' is not defined
>>> python madlib.py
SyntaxError: invalid syntax
>>> C:\Users\Shawn\Documents\Pydoc\madlib.py
SyntaxError: invalid syntax
>>> python C:\Users\Shawn\Documents\Pydoc\madlib.py
SyntaxError: invalid syntax
>>> $ python C:\Users\Shawn\Documents\Pydoc\madlib.py
SyntaxError: invalid syntax
>>> import madlib.py
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import madlib.py
ImportError: No module named madlib.py
I then navigate using the IDLE "file - open " command and when choosing the file
the IDLE blinks and it runs the program showing...
>>> ================================ RESTART ================================
>>>
And then runs the program.
If I then type
>>> import madlib.py
It runs the program.
If I type it again…
>>> import madlib.py
I get the traceback error.
I know these are very simple questions - but in order to get into the nuances of
programming itself - I have to get past these system level errors… and be able
to manipulate the files I create.
Question 2: How does one create/add a default directory to python? I don't
seem to have permissions to write files to my python folder on windows 7, which
is another matter….
For instance I'd like to save a program I'm using called madlib.py to
"C:\Users\Shawn\Documents\Pydocs" and be able to access it through the command
line or through Idle without having to type the path…