tech:python_cours_formation
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| tech:python_cours_formation [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:python_cours_formation [2026/05/30 17:15] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Python cours formation | ||
| + | |||
| + | ~~~ | ||
| + | >>> | ||
| + | The Zen of Python, by Tim Peters | ||
| + | |||
| + | Beautiful is better than ugly. | ||
| + | Explicit is better than implicit. | ||
| + | Simple is better than complex. | ||
| + | Complex is better than complicated. | ||
| + | Flat is better than nested. | ||
| + | Sparse is better than dense. | ||
| + | Readability counts. | ||
| + | Special cases aren't special enough to break the rules. | ||
| + | Although practicality beats purity. | ||
| + | Errors should never pass silently. | ||
| + | Unless explicitly silenced. | ||
| + | In the face of ambiguity, refuse the temptation to guess. | ||
| + | There should be one-- and preferably only one --obvious way to do it. | ||
| + | Although that way may not be obvious at first unless you're Dutch. | ||
| + | Now is better than never. | ||
| + | Although never is often better than *right* now. | ||
| + | If the implementation is hard to explain, it's a bad idea. | ||
| + | If the implementation is easy to explain, it may be a good idea. | ||
| + | Namespaces are one honking great idea -- let's do more of those! | ||
| + | ~~~ | ||
| + | |||
| + | Voir : | ||
| + | * PEP 8 | ||
| + | * pep257 | ||
| + | |||
| + | Formations : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Apprendre en ligne | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Bases : | ||
| + | * https:// | ||
| + | * [Types et variables du langage python](http:// | ||
| + | * Listes / tuples : https:// | ||
| + | * Itérateurs | ||
| + | * Générateurs | ||
| + | * Décorateurs | ||
| + | * Web framework : Django, Flask, Pyramid, connexion, hug | ||
| + | * Parsing : ElementTree (XML), Yaml, Json | ||
| + | * Science : [Numpy](https:// | ||
| + | * Introspection : (dir, help) module inspect '' | ||
| + | * Boucle : émuler un switch_case, | ||
| + | * Mots clefs et fonctions utiles : with, any, all... | ||
| + | * Programmation fonctionnelle : lambda, map, filter, reduce, itertools.filterfalse | ||
| + | * Fonction Lambda https:// | ||
| + | * Script système : sys os platform syslog | ||
| + | * Fonction : Arguments par défaut, '' | ||
| + | * émuler un switch_case | ||
| + | * Complexité et preuves algorithmiques | ||
| + | * Base de données ORM | ||
| + | * Design Patterns < | ||
| + | |||
| + | Avancé : | ||
| + | * Solutions d' | ||
| + | * Interfaçage avec C / C++ [Swig](https:// | ||
| + | * Typage statique avec mypy et le module typing | ||
| + | * Les annotations de types (avec mypy, pypright, pyre ou pytypes) | ||
| + | * Programmation par contract avec PyContracts | ||
| + | |||
| + | Linter / Formater : | ||
| + | * Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * black (The uncompromising code formatter) | ||
| + | * pydocstyle (checking compliance with Python docstring conventions) | ||
| + | * autopep8 | ||
| + | * flake8 (enforcing style consistency across Python projects) | ||
| + | * ruff (linter et formateur Python) - https:// | ||
| + | * pylint (linter to detect various errors) | ||
| + | * isort (simplify import) | ||
| + | * bandit | ||
| + | * Autres : tox | ||
| + | * Jedi for Completions, | ||
| + | * Rope for Completions and renaming | ||
| + | * Pyflakes linter to detect various errors | ||
| + | * McCabe linter for complexity checking | ||
| + | * autopep8 for code formatting (preferred over YAPF) | ||
| + | * pycodestyle | ||
| + | * prospector | ||
| + | * pre-commit | ||
| + | |||
| + | |||
| + | Gérer les exceptions et les erreurs : | ||
| + | * try except finally | ||
| + | * raise | ||
| + | * Exception | ||
| + | * assert | ||
| + | * traceback | ||
| + | * pdb | ||
| + | |||
| + | Les Libs: | ||
| + | * [Awesome-python](https:// | ||
| + | |||
| + | |||
| + | P.O.O. | ||
| + | * Attributs et méthodes de classe/ | ||
| + | * Les méthodes spéciales (surcharges d' | ||
| + | * Héritage, surcharge, polymorphisme, | ||
| + | * L’héritage simple, l’héritage multiple et le polymorphisme | ||
| + | * L' | ||
| + | * Bonnes pratiques de la programmation objet avec Python | ||
| + | * Les méta-classes et l' | ||
| + | |||
| + | |||
| + | |||
| + | La stdlib - Parcours de quelques modules phares : | ||
| + | * gestion de fichiers | ||
| + | * argparse | ||
| + | * logging (Gestion des logs avec Python) https:// | ||
| + | * configparser | ||
| + | * os | ||
| + | * sys | ||
| + | * sh | ||
| + | * subprocess (shell, bash, commands) voir https:// | ||
| + | * re (expressions rationnelles) | ||
| + | |||
| + | Docker / Containers : | ||
| + | * [A beginner' | ||
| + | |||
| + | Aller plus loin | ||
| + | Présentation des objets et fonctions avancés | ||
| + | * context managers (with) https:// | ||
| + | * documenter avec sphinx | ||
| + | * Packager une application en Python | ||
| + | * Créer des tests unitaires dans son application : pytest, Testinfra, hypothesis, unittest, docstests | ||
| + | |||
| + | |||
| + | ## Les fonctions | ||
| + | |||
| + | ~~~python | ||
| + | def create_hello_world_message(name : str) -> str: | ||
| + | """ | ||
| + | Creates a personalized greeting message for the given name. | ||
| + | |||
| + | Parameters: | ||
| + | - name (str) : The name for which the message is created. | ||
| + | |||
| + | Returns: | ||
| + | - hello_world_message (str) : A personalized greeting message for the given name. | ||
| + | |||
| + | Raises: | ||
| + | - ValueError : If the given name is empty or None. | ||
| + | """ | ||
| + | |||
| + | if not name: | ||
| + | |||
| + | raise ValueError | ||
| + | |||
| + | hello_world_message = f' | ||
| + | |||
| + | print(f' | ||
| + | print(f' | ||
| + | |||
| + | return hello_world_message | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Import | ||
| + | |||
| + | ~~~python | ||
| + | import os | ||
| + | import sys | ||
| + | sys.path.append(os.path.dirname(os.getcwd())) | ||
| + | |||
| + | import plop | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Sciences - math | ||
| + | |||
| + | ~~~python | ||
| + | from sympy import symbols, Eq, solve | ||
| + | |||
| + | B, G = symbols(' | ||
| + | eq1 = Eq(B, 0.3 * B + 5 * G) | ||
| + | eq2 = Eq(100 * B + 200 * G, 1000) | ||
| + | solution = solve(eq1, eq2), (B, G)) | ||
| + | solution[B] | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## Mutable / immutable | ||
| + | |||
| + | Voir aussi : deepcopy | ||
| + | |||
| + | ~~~python | ||
| + | lst=[1, | ||
| + | print(list(map(lambda x: [x],lst))); | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | ~~~python | ||
| + | import random | ||
| + | random.randint(1, | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | export PYTHONUNBUFFERED=1 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Linter | ||
| + | |||
| + | ### Flake8 | ||
| + | |||
| + | ~~~ | ||
| + | ansible-csv-inventory.py: | ||
| + | ~~~ | ||
| + | |||
| + | Pour ignorer l' | ||
| + | |||
| + | `tox.ini` | ||
| + | ~~~ini | ||
| + | [flake8] | ||
| + | extend-ignore = E501 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | ~~~bash | ||
| + | $ ansible-test sanity --list-tests | ||
| + | action-plugin-docs | ||
| + | ansible-doc | ||
| + | changelog | ||
| + | compile | ||
| + | empty-init | ||
| + | ignores | ||
| + | import | ||
| + | line-endings | ||
| + | no-assert | ||
| + | no-get-exception | ||
| + | no-illegal-filenames | ||
| + | no-smart-quotes | ||
| + | pep8 | ||
| + | pslint | ||
| + | pylint | ||
| + | replace-urlopen | ||
| + | runtime-metadata | ||
| + | shebang | ||
| + | shellcheck | ||
| + | symlinks | ||
| + | use-argspec-type-path | ||
| + | use-compat-six | ||
| + | validate-modules | ||
| + | yamllint | ||
| + | ~~~ | ||
