This tutorial will run through using cpython on DSC machines.

Click on any image to view it in a lightbox.

The Basics

For starters, let's get python to run the eponymous hello world program. The first thing to do is navigate to your preferred source code storage location, and write the hello world program.

The Hello World program in a usable folder.

Then, start the command prompt.

Use the search feature in the Start menu if you're stymied.

And then navigate to your program location.

Use cd to change directory, dir to list contents of the current directory.

Then, run the python interpreter.

python HelloWorld.py

Other Features

At some point you may build up a code library that you would like to reference. Python contains options to ease the reuse of old code. In order to explore these options, lets compute the factorial of five. First, go to your prefered source directory, and write the program. The program is split up into two files: one that contains a factorial algorithm inside a module, and one that makes use of that module. The two files are split into disparate directories.

A factorial function in a module, located in a different folder than the main program.

Start up the command prompt and navigate to the folder containing the main program. Now, whenever python runs, it searches for code libraries based on the environment variables PYTHONHOME and PYTHONPATH. In order for python to be able to find the factorial function, its folder must be on the PYTHONPATH. So, set the variable (on Windows, setting a variable in the command prompt only affects that command prompt).

SET PYTHONPATH=..\SomeOfMyLibraryCode

Now just run the main program, and you should find that 5! = 120.

python FacFive.py

Dept. of Scientific Computing
Florida State University
400 Dirac Science Library
Tallahassee, FL 32306-4120
Phone: (850) 644-1010
admin@sc.fsu.edu
© Scientific Computing, Florida State University
Scientific Computing