Notes from Python lab 1, Tuesday 2007.09.25 1. Python can be run interactively by typing "python" at the $ shell prompt. You will see the >>> prompt. You can interactively do Python statements, or you can import a Python script that has definitions followed by commands. The chaos.py example on page 12 of the textbook shows how to import a script. Note that the main() function is both defined and then later called in the script. For this example, the main() function will be called (and your program executed) when the script is imported. Be sure your script has two blank lines after the doubly indented defintion of the main() function before the next statement calling main() on the last line of the file. 2. The preferred way to develop Python programs is to edit them in a file with your favorite editor and run them in another command line window. Regarding the editor, the scite editor on the lab systems has Python formatting built in, as does vi and emacs. For executing your programs, you can import your scripts as shown on p12 and p13 of the textbook, or you can enter "python myscript.py" at the shell command prompt. The problem I've had with the import method is that any changes I make to the file seem to require me to re-start the Python interpreter in order to import the new changes to the file. This doesn't seem right to me, so I prefer the command line method for executing Python programs. 3. We used the following simple set of Unix commands in the lab: passwd change password in Linux pwd print working directory ls list the files in the working directory mkdir make a new directory cd change directories to the directory cd change back to your home directory more scrool through in the terminal window. rm remove cp copy file to file . mv move file to file (ie, rename to ). lpr send to the printer nano edit You should keep your work organized in your directory. I recommend separate python directory and a separate directory under the python directory for each chapter of the textbook. When you run the python interpreter, be sure you start it in the same directory as the files that contain your Python scripts. 4. Isaac showed us how to create a directory "web" in our home directory and access any files in that directory from a web browser anywhere in the world. You can build your own web site there.