You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

python-11.md 999 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. % Programmation avec Python (chapitre 11)
  2. % Dimitri Merejkowsky
  3. \center \huge Retour sur les exceptions
  4. # A quoi sert finally?
  5. ```python
  6. try:
  7. fp = open("file.txt")
  8. 1 / 0
  9. except ZeroDivisionError:
  10. print("got you")
  11. finally:
  12. print("closing")
  13. fp.close()
  14. ```
  15. versus:
  16. ```python
  17. try:
  18. fp = open("file.txt")
  19. 1 / 0
  20. except ZeroDivisionError:
  21. print("got you")
  22. fp.close()
  23. ```
  24. # Réponse:
  25. Que se passe-t-il si l'exception *n'est pas* ZeroDivisionError?
  26. \center \huge Utiliser des bibliothèques tierces
  27. Plan:
  28. - sys.path
  29. - difference debian/arch
  30. - in $HOME
  31. - PYTHONPATH
  32. - so how do we put the code from pypi.org inside sys.path?
  33. - setup.py
  34. - pip
  35. - example with tabulate
  36. - TODO: example with more deps
  37. - problemes:
  38. - un seul .local/bin sur linux :/
  39. - 2 projets avec des versions de deps differentes
  40. # The rules
  41. * One virtualenv per project
  42. * One virtualenv per Python version
  43. * Only use pip from *inside* a virtualenv
  44. Tuto:
  45. * let's install tabulate and requests