0% found this document useful (0 votes)
65 views

Module 1: Introduction To Python

This document provides an introduction to using Python through the Jupyter Notebook and Spyder interfaces for a course on Python. It discusses installing Python and downloading example files, how to open and run Jupyter notebooks, modifying and executing code cells, and using plotting commands. It also briefly explains running notebooks through the Microsoft Azure server and using the Spyder GUI to open, run, and debug Python scripts. An example plotting script and a quiz solving script are presented to demonstrate functionality.

Uploaded by

Sruti Smriti
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Module 1: Introduction To Python

This document provides an introduction to using Python through the Jupyter Notebook and Spyder interfaces for a course on Python. It discusses installing Python and downloading example files, how to open and run Jupyter notebooks, modifying and executing code cells, and using plotting commands. It also briefly explains running notebooks through the Microsoft Azure server and using the Spyder GUI to open, run, and debug Python scripts. An example plotting script and a quiz solving script are presented to demonstrate functionality.

Uploaded by

Sruti Smriti
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Module 1: Introduction to Python

Lars P. Mikkelsen, DTU Wind Energy

Installation and introduction to the scripting language Python


- Jupyter Notebook interface
- Spyder interface
Introduction to Python
During some of the lectures in the course, Python will be used as the scripting language. It will
be used through the Jupyter notebook interface or through the Spyder GUI. In the following,
an introduction to how to get started will be given

• Installation
– Install python on you own computer going to the following link and chose the newest
version for you operation system
– https://www.continuum.io/downloads

• Download the example files in a folder of your chose. Tthe Jupyter notebook and the python
files have the extensions
Jupyter notebook files: *.ipynb
Python files: *.py
Jupyter Notebook (1/3)
In order to start the Jupyter notebook code (.ipynb) you can e.g. do the following in Windows
• Right click (with the shift key down) on the folder where the code is located and chose “Open
command window here

• In the command window write the following


– “jupyter notebook Filename.ipynb” where the file name can be completed using the
<TAB> key
Jupyter Notebook (2/3)
• If you have started the introduction Jupyter file, the following window should show up

• If you double click on a cell (both text and commands), you can modify the content. By
pressing <Ctrl>+<Enter>, you will execute the code. You can run the full code by go to the
menu: “Cell->Run All”. If you want to reset all variables you should run one of the Kernel
reset/restart menu point. The type: “Markdown” or “Code” indicate whether the specific cell
is text or a Python code sequence.
Jupyter Notebook (3/3)
• Use e.g. 15 minutes explore the notebook and try e.g. to modify some of the code sequences
and re-run it.
• The way the plotting of curves occurs can be defined by using one of the following two
jupyter notebook specific commands where the first version just show the curves on the page
while the second version are given a zoom able versions of the plots. If the second option
gives empty plot windows, you may need to rerun that specific cell by pressing
<Ctrl>+<Enter>
Jupyter Notebook over a server
• As an alternative of installing Jupyter notebook yourself, the code can also be runned over a
server. As a demonstration, I have uploaded the script to the “Microsoft Azure Notebook”.
Sometime, the graphic part does not come correctly in the preview and you need to run it
yourself
– https://notebooks.azure.com/anon-x8vbbq/libraries/46W17

• If you want to modify and run it yourself through the server, you need to have your own
account on “Microsoft Azure Notebook”. Users at DTU can use there DTU-login in order to get
access to that.
Spyder GUI (1/3)
• The spyder gui, you can
start from the icon

• In order to open up the py-


script, simply drag that into
the editor part and click on
the green arrow at the top
menu in order to run the
script
Spyder
GUI
(2/3)
Spyder GUI (3/3)
• In the GUI, you can similar to e.g. the matlab gui
explore the variable content etc.
• In order to reset the variables and restart the python
kernel, also if you script is hanging you can press
<Ctrl>+<.> given the option

• If you as alternative of having the plotting windows as


inline windows, you can have them open up in
separate windows where you can zoom, save etc. by
make the following change to the preferences:
Example
on a
simple
plotting
script
Example on
solving a quiz
question

You might also like