Getting Started

Overview

Teaching: 10 min
Exercises: 0 min
Questions
  • How do I use the Spyder IDE?

  • How can I run Python programs?

Objectives
  • Learners can launch the Spyder IDE

  • Learners are able to use the iPython console to interact with Python

  • Learners are able to write code in the Spyder editor and run this code

  • Learners are able to save their code in a *.py file

  • Learners can use the different buttons and panels needed in the Spyder IDE

Use the Spyder IDE for editing and running Python.

Different ways of interacting with Python using Spyder

Python in the console

Go to the iPython tab at the bottom right. What happens when you type a small calculation there? For example, what happens when you type the following calculation and press enter?

7 * 3

Solution

Python returns the result of the calculation.

21

Python in the editor

The large panel on the left probably has some text in it that looks like this:

"""
Spyder Editor

This is a temporary script file.
""" 

Write the following line below these lines and press run (the green ‘play’ button or f5). A window might pop up asking you to specify the run settings, leave the settings as they are and press ‘Run’. What happens?

print('Hello world!')

Solution

In the iPython console Python tells you which files it ran and the result of this run

runfile('/home/ylja/.config/spyder-py3/temp.py', wdir='/home/ylja/.config/spyder-py3')
Hello world!

Saving the code

To save the code, press ‘file’ and then ‘save as’. Now give the file a name, for example ‘mycode.py’ and save it in a directory/folder where you know how to find it. Look into your file system the way you usually do it. Is the file where you expect it to be?

Key Points

  • Use the Spyder IDE for editing and running Python

  • The iPython console can be used to interact with python directly

  • The editor can be used to write code, run and save it