Computational Economics @ Bundesbank
Python:
Historically, python was a glue language used to interoperate many low-level/system languages.
It has been increasingly used for web-development (cf django)
Nowadays it is the lingua franca of machine learning
Most major machine learning / deep learning libraries have python bindings
def say_hello(name):
"""This function prints morning greetings"""
print(f"Good morning {name}!\n")
# we can import libraries
import datetime
t = datetime.datetime.now()
# blocks are defined by indentation and colons
if (t.hour,t.min) <= (9,15):
print("All good?\n")
else:
print("Time to get started?\n")
say_hello("Pablo")
Windows
Linux
Web
There are several flavours of Python:
Interpreted language
In an interpreted language, instructions are read and translated into processor instructions, one after another.
As consequence, it is:
A file ending with .py is a python module
program.py
The content from a module can be imported
To import all objects in a module (functions, strings, …)
A folder containing modules and an __init.py__
is a package
.
import a package or a submodule:
import package
from package.submodule import something
The content of modules and submodules is evaluated only once.1
It is actually precompiled.
This is perfect for distributing a package.
Not so much to develop code interactively.
Several ways to create / distribute python packages have been developped over the years.
There are essentially two kinds of packages:
pip files (what are eggs btw)
can be installed with pip install package
no dependency solving ! no proper uninstallation !
pip files a virtual evnironment created with venv
reproducible setup can be described in
directory specific environments can be managed with poetry
or venv
:
python -m venv directory
conda files
installed in a conda environment
with proper / reversible dependency solving
mamba
or micromamba
reproducible environment can be described in:
directory specific environments can be managed with pixi
Let’s setup the environment specified in requirements.txt
Move to python syntax tutorial