Browse Source

more contents

master
Dimitri Merejkowsky 5 years ago
parent
commit
8dc8fbd92f
1 changed files with 38 additions and 16 deletions
  1. +38
    -16
      sessions/python-11.md

+ 38
- 16
sessions/python-11.md View File

@@ -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