Friday, March 20, 2009

Loading Python Scripts From A CD and Saving

If you load a Python Script from a CD from your book into your text editor, it is then impossible to simply click save button in the text editor to save over that script. The reason for this is the fact that you are trying to save to a read only CD/DVD and this is an impossible task.

Yes its true there are read write CDs/DVDs but once a CD/DVD is fixed so that it runs on every computer and OS then it is no longer Read Write this is even true for Read Write CDs/DVDs. Manufactures of books commercial software always have their CDs/DVDs fixed so that they can distribute them to work on as many computers as possible.

So rather you have to save to your hard drive, thumb drive, USB Hard Drive with the File->Save As.

Thursday, March 19, 2009

Python Programming In Windows

The Easy Way:
Go To Start->Run
now type cmd and press enter
now you are at the prompt.
now you need to change directories into your python installation folder
now in order to run your python program from the prompt if python program is in the same director with the python installation folder, if it is not then move it to this folder, now you will want to type:

python.exe yourprogramnamehere.py

The Hard Way: I don't feel like listening to the instructor and I want to do what I want to do.
Go To Start->Run
now type cmd and press enter
now you are at the prompt.
now comes the fun. Type out your full installation path for your python program and the full path to where your file resides everytime you want to debug your program which will be quite often until you get rid of all of your syntax errors and logic errors. This will add a good bit of time to your debugging process.

The entry at the command prompt will look something like this and will wrap around several lines at the prompt.

C:\Python26\python.exe C:\Documents And Settings\02402530235\My Documents\Python Programs\yourpythonprogramhere.py

Yes you can run your programs in Idle but you won't get the detailed error messages that you need in order to debug your program. Its best to use the command prompt instead. Now that is just for running the program not counting setting up JEdit.

Setting Up JEdit:
Go To Utilities->Global Options

Click On Gutter
Line Numbering Checked
Now you can click on Monospace 10 and change the font size larger than 10 so you can actually see the line numbers.

Click On Text Area
Now you can change the font size and font if you like by clicking on the button to the right of Text Font.

You must save your file as a .py before text highlighting will show up for your python code in JEdit.

Python Programming Basics With Ubuntu Linux

In the terminal you can run your python programs:
Go To Applications->Accessories->Terminal

python yourprogramhere.py


Note you need to be in the same directory as your python program, otherwise you need to type:

python /fulldirectorypath/yourprogramhere.py

or

python ./remainingdirectorypath/yourprogramhere.py

if you only type python at the prompt then you enter into the python program where it expects you to code in python commands at that point and time. Don't do this instead code your python programs in the text editor and run them with the python command.

Tip you can cycle through your previously typed commands in Linux by hitting the up and down arrows on the keyboard at the prompt.

Go To Applications->Accessories->Text Editor
in the Text Editor go to View->Highlight Mode->Scripts->Python
in the Text Editor go to Edit->Preferences
in Preferences make sure the following is checked:

in the View Tab
Text Wrapping All Options Checked
Display Line Numbers Checked
Highlight Current Line Checked
Display Right Margin Checked and leave it at 80
Highlight Matching Bracket Checked

in the Editor
Tab Width leave it at 8
Insert Spaces Instead of Tabs DO NOT CHECK!!!! This will keep your python programs from running correctly do to the fact that it relies on tabs for the begin and ending parts of code blocks such as functions, condition statements, etc.
Enable Automatic Indentation Checked.
File Saving Check All

in the Font & Color Tab
Use The System Fixed Width Font Do Not Check.
Now you can select a larger font which will make it easy to read your code and debug faster.

Now you are ready to code your program in Python in the text editor and save your file with the extension .py

After you save your file test the program in the terminal with your python command as explained up above. If you make a syntax error you will get detailed messages of what the problem is and what line the error is on. The error messages are better in the terminal than they are in Idle.

Monday, March 2, 2009