From 8dc8fbd92f06a3f4572d36ee21d8186a1c6e04ba Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Fri, 3 May 2019 13:30:44 +0200 Subject: [PATCH] more contents --- sessions/python-11.md | 54 ++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/sessions/python-11.md b/sessions/python-11.md index b885162..a82ed28 100644 --- a/sessions/python-11.md +++ b/sessions/python-11.md @@ -3,7 +3,7 @@ \center \huge Retour sur les exceptions -# A quoi sert finally +# A quoi sert finally? ```python try: @@ -16,29 +16,51 @@ finally: fp.close() ``` -Que se passe-t-il si on remplace `1/0` par -`my_list[42]` ? +versus: -\center \huge Libraries tierces +```python +try: + fp = open("file.txt") + 1 / 0 +except ZeroDivisionError: + print("got you") -# Introduction: pip +fp.close() +``` -* python3 -m pip -* `--user` +# Réponse: -But: what about several projects? +Que se passe-t-il si l'exception *n'est pas* ZeroDivisionError? -# Virtualenvs -# pip + virtualenv = <3 +\center \huge Utiliser des bibliothèques tierces -# Tuto +Plan: -* Let's install requests! +- sys.path +- difference debian/arch +- in $HOME +- PYTHONPATH -``` -# avant +- so how do we put the code from pypi.org inside sys.path? +- setup.py -# après -``` +- pip + +- example with tabulate +- TODO: example with more deps + +- problemes: + +- un seul .local/bin sur linux :/ +- 2 projets avec des versions de deps differentes + +# The rules + +* One virtualenv per project +* One virtualenv per Python version +* Only use pip from *inside* a virtualenv + +Tuto: +* let's install tabulate and requests