[pythonvis] Some suggestions for windows users

  • From: "Richard Dinger" <rrdinger@xxxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Sat, 3 May 2014 10:48:24 -0700

Here are a few Suggestions that may save you some time.  These suggestions 
apply to Windows computers running jaws that are using the shell.bat command 
shell from the getting started message.  The terms program and script are 
interchangeable when discussing Python code.

1 Running a script in your command shell
When python is installed on your windows machine the python compiler is 
associated with files ending in .py just like Notepad is associated with .txt 
files and Word is associated with .doc files.  That means the python compiler 
is the default program to run when a .py file is selected.  So most of the time 
after the c> prompt in your command shell instead of typing:
c> c:\python27\python.exe hello.py

you only need to type:
c> hello.py

You can then review the program output and any program errors by reading 
through the text immediately above with the jaws cursor.  If the program output 
is large, you can redirect the output to a text file.  For example, if you want 
the output directed to file test.txt and error messages directed to the screen 
type:
c> hello.py >test.txt

And if you want both output and error messages directed to file test.txt use:
c> hello.py >test.txt 2>&1


2 A typical write-run-debug test development cycle
If you use the shell.bat command shell that I suggested, start both the shell 
and your text editor in the development directory.  Open your source file, type 
in your script and save it.  At the prompt in the shell type the script name.  
Check out any errors (use jaws cursor if needed).  Switch (alt+tab) back to 
editor, revise code and save.  Switch back to shell, hit up arrow and then 
enter to run the script again.  Repeat cycle until no errors.


3 Using the syntax error carrot
When a syntax error is found in your source file the error message includes a ^ 
symbol in the line below the offending line.  The ^ is trying to indicate the 
error.  Go to the line with the ^ and move your cursor to the ^, move directly 
up and then move back and forth with the right and left arrows to see where you 
are in the line.  This may help.  The ^ points to where Python first realized 
there was an error, not necessarily the actual error.  But it does put you near 
it, so look around carefully maybe the previous line.


4 Running a finished script in windows explorer
Relying on the association of .py files and the python compiler, you can run a 
script in explorer by simply hitting enter on the file.  The only problem is 
windows runs it by opening a window, running the script and then closing the 
window, which happens so fast you will miss it.

So here is a technique that you can use, but it only works if the script is 
error free.  At the end of your script add the line:
raw_input("press enter to continue")

When the line is reached, the script will print the quoted message and pause 
and wait for you to press enter, but only if there were no errors.  So if the 
message does not appear, the script stopped prematurely and will have to be run 
in the shell to see the error.

Other related posts:

  • » [pythonvis] Some suggestions for windows users - Richard Dinger