Appendix: Standalone Programs

Appendix: Standalone Programs#

So far, we have seen how to write code in Jupyter notebooks. That works well for some purposes, but sometimes we want to create standalone Python programs. Python programs are usually stored in files with names that end with .py.

Let’s go back to one of our earliest examples, and make a Python file containing this program:

print('See you in court')

We can save this program in the file see_you.py.

The easiest way to run a Python program is by double-clicking the program file. If we want to pass arguments to the program, we must start it from a command-line prompt.

There are different ways to open a command-line prompt. In Windows the command-line is called Command Prompt or cmd, while in Mac OS there is the program Terminal. However, if you use the Anaconda Python distribution, you should use Anaconda Prompt.

After you open the command-line prompt, you must usually navigate to the correct directory with the command:

cd <directory>

Then, we start Python with our program as an argument:

python3 see_you.py