Getting started

Before we dive into Python, let’s get familiar with the environment we are going to use to program and run Python. The two main components you will need to use Python are

  • A terminal/console
  • A text editor

*nix Users

If you are continuing on from the UNIX/Linux course and would like to continue to use that, or are using your own Linux machine or MacOS, you should already be familiar with your terminal program and editor.

For the remainder of these notes we will, where needed, show how to use win and *nix (*nix being a common term for “unix-like”).

An editor

As Python code is human readable text, we need a text editor of some sort to read and edit Python code.

Jargon

If the text editor has features like syntax highlighting (colour coding words in the code based on whether ther refer to functions, known keywords, etc), code completion, and other goodies, it’s called a code editor. If it is embedded in an interface that also has a terminal and sometimes a variable browser, the whole program is referred to as an Integrated Development Environment (IDE). Spyder and PyCharm are two such IDEs specific to Python.

For the windows users amongst you, we will be using Notepad++ as this is similar to Notepad but adds things like syntax highlighting.

In the Start Menu, find Notepad++, either by looking through the programs or by using the search field.

*nix users

If you are already comfortable with your editor of choice, keep using that. For the rest of you pluma is the standard text editor included with the MATE desktop environment (gedit on other systems).

The terminal

In order to run Python scripts we will use a pre-configured command prompt provided by WinPython.

In the Start Menu, find WinPython Command Prompt, either by looking through the programs or by using the search field.

To run a script from the terminal use

python scriptname.py

*nix users

Luckliy for you, Linux (and to some extent MacOS) systems make development much more straight-forward!

The ubuntu systems on openstack have had Python installed on them, and all terminals get preconfigured by the installation processes.

On MacOS, you will need to use the Anaconda terminal (or have correctly configured your standard terminal to use Anaconda instead of the built-in Python).

Getting help

As well as asking the demonstrators, you are encouraged to get used to using online resources. Simply searching for e.g.

python FUNCTIONNAME

(and replacing FUNCTIONNAME with the name of the function you want help on!) using your favourite search engine will almost always return relevant help.

While the demonstrators are there to help you get started and provide detailed help when you need it, it will be very beneficial to you in the long run to become familiar with what online sources there are and how to optimize your searches to most quickly find the answers you need.

Resources I often use are:

Advanced Users

Another simple way of getting help is to use the interactive help system in the IPython console. The IPython console is an interactive Python session, i.e. it looks like a terminal but instead of accepting terminal commands, it accepts Python code directly. The IPython console has several useful features to get help including

  • help(FUNCTIONNAME) prints help on the function called FUNCTIONNAME
  • FUNCTIONNAME? prints help on the function called FUNCTIONNAME
  • MODULENAME. and then pressing tab (twice) shows a list of all functions available in the module called MODULENAME (if it’s imported).