from IPython.core.display import HTML

HTML(open("custom.html", "r").read())
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright (C) 2014-2023 Scientific IT Services of ETH Zurich,
Contributing Authors: Uwe Schmitt, Mikolaj Rybniski

About me¶

  • My name is Uwe Schmitt
  • I work for Scientific IT Services of ETH
  • I started to use Python in 2003
  • Python is still my favorite all purpose language

About Scientific IT Services (SIS)¶

https://sis.id.eth.ch¶

  • group of connected experts from different backgrounds
  • assist researchers in IT related issues

Fields:

  • HPC: we run Euler computing cluster and offer consultancy
  • Data management: we developed and maintain openBIS and offer consultancy (like data management plans)
  • Computational science: we offer consulting related to data analysis and programming
  • Datascience and Machine Learning support
  • On demand software development
  • We take over and maintain software
  • We offer courses
  • We offer code and data clinics
  • ...

About this course¶

  • Introduction to basic topics and concepts

  • We can not learn all Python features

  • Exercise section for every topic:

    • check questions usually don't require programming
    • Programming exercises
    • Homework
    • Optional exercises
  • Your programming speed will vary, so: some of you will not manage to solve all exercises in the given time, this is why we have some optional exercises.

Python versions as of January 2023¶

  • Python 3.11 is the last stable version, we use this version in the workshop
  • Python 3.12 is under development

Python distributions¶

  • Official versions from http://python.org

  • Anaconda: https://www.anaconda.com/products/individual

    • ships with many packages for science
    • not loved by euler administrators scince this includes many files which put presure on the file system.
  • Miniconda: https://docs.conda.io/en/latest/miniconda.html

    • minimalistic version of Anaconda
  • Linux distributions ship with Python usualy, Mac also, might not be up-to-date though.

  • pyenv: https://github.com/pyenv/pyenv

    • in case you don't want to use Anaconda/miniconda but the Python from your OS distribution is too old or you want to try early releases.
    • Also helps to separate Linux/Mac included Python from your own Python.

Usefull links¶

  • get Python: http://python.org/downloads
  • official documentation: https://docs.python.org
  • PyCharm (IDE): https://jetbrains.com/pycharm
  • Visual Studio Code (IDE): https://code.visualstudio.com/
  • Jupyter lab: https://jupyter.org/
  • Hitchhiker's Guide to Python: https://docs.python-guide.org
  • Python Module Of The Week (PyMOTW): https://pymotw.com/3
  • Scientific Python lectures: http://www.scipy-lectures.org/intro/

About Python¶

  • easy to read syntax and easy to learn

  • interpreted language, no compilation step needed:

    • no compilation time
    • but slower execution
  • supports efficient programming: Python Code is usually 3-5 times shorter than Java Code and 5-10 times shorter than C++ code.

  • multi paradigm: object oriented, procedural and functional concepts

  • huge eco system of external libraries (Python packages, "batteries included")

  • multi purpose: scientific applications, web frameworks, game programming, ...

  • open source, thus supports reproducible science.

  • platform independent (almost)

Increasing popolarity according to google searchs for tutorials¶

The y-axis has logarithmic scaling ! So what you see as a line is actually exponential.

The inventor of Python: Guido van Rossum

https://en.wikipedia.org/wiki/Guido_van_Rossum

How to use this script¶

  • the square boxes contain code

  • below such a box you see the output

  • try to match output to code

  • Dont copy-paste !

Python Development Environments¶

jupyter has strengths and some weaknesses.

Benefits:

  1. Convenient for teaching and demonstrating code.
  2. Helpful for data science tasks. Supports plotting in the notebook.
  3. Convenient for prototyping or playing with Python and Python libraries.

Drawbacks:

  1. You can execute cells in different orders giving different results. And the output does not show in which order cells were executed.
  2. Version control with git is inconvenient for jupyter notebooks.

For programming beyond 100 lines of code I recommend the integrated development environments (IDEs)

  • PyCharm (https://www.jetbrains.com/pycharm/), free community edition, many features
  • Visual Studio Code (https://code.visualstudio.com/), free, setup instructions for Python at https://code.visualstudio.com/docs/python/python-tutorial, less heavy and faster than PyCharm.
  • spyder (https://www.spyder-ide.org/) IDE which attempts to mimic the Matlab environment.

Working with Jupyter¶

We use jupyter notebooks for teaching as you can mix documentation and code execution.

  1. Enter print(42) in the cell below
  2. Press SHIFT + RETURN to run the code
  3. You should see 42 below the cell.
  4. You should also see a new code cell to enter more code.