Saint Louis University |
Computer Science 1020
|
Computer Science Department |
If you are using your account on our department's hopper system, or our labs in Ritter Hall, Python is already installed on those machines.
It is also relatively easy to install Python on your own computer. In fact, if you have an Apple computer, Python2 is already pre-installed as part of the OSX distribution. For other platforms, you can download a Python installer from www.python.org/download; make sure to download the Python 2.x line (Python 2.7 is the most current release).
The Python interpreter is a piece of software that you run on the operating system in order to interpret Python commands that you type or Python source code that you have saved in a file. There are two typical ways that you can execute the interpreter:
For the most user-friendly experience, we recommend using IDLE for all
your Python development, because it provides an integrated text editor
that can highlight Python syntax, and because its menus allow for some
convenient integration with other aspects of the language. Depending
on your system, you might be able to find a menu item for IDLE in a
typical "start" menu, or to set your operating system to associate
IDLE as the application that should be launched when double-clicking on
Python code saved with the conventional idle
at a terminal console. Similarly, on OSX, you will want to open a
terminal console and type the command, idle.
We note that there is a bit of an inherent slowdown when running Python programs within IDLE rather than directly in the interpretter, so for large-scale computations it is often helpful to know how to run a script directly. This can be done through a typical commandline interface in a terminal window (or command prompt on Windows). You can start the Python interpreter without a script using the simple terminal command
pythonor you can have it immediately execute an existing script, such as myscript.py, with the terminal command
python myscript.pyThat will cause the script to run to completion and then end the python process. However, this above command is only recognized if you're Python installation installed the python command within your default "path". That will already be the case on most OSX/Linux systems, but it is not done automatically for Windows. You can instead adjust your path variable in user settings, or you can instead give a fully-qualified address of where that Python command is found (which depends on your system), but might be something usch as
C:\Python27\bin\python myscript.py
Finally, on any system the above command also assumes that you're current working directory is the one in which the file myscript.py is found. Uusually when you start a new terminal console the working directory is your home directory. You can change directories using the command cd, using a syntax perhaps such as
cd Desktop/csci1010 python myscript.pyif it were the case that myscript.py were stored nested within a folder Desktop/csci1010 or adjusted to whereever you chose to save your script.
There is a wonderful web site named pythontutor.com that allows you to walk through the execution of a Python program, step-by-step, with a visual display of the current work space.