Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| python:accueil [2024/01/28 20:23] – [Divers] move float stuff to its own section and add math.isnan phsw | python:accueil [2025/09/04 09:32] (Version actuelle) – [Chaînes de caractères] add link phsw | ||
|---|---|---|---|
| Ligne 17: | Ligne 17: | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| + | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| Ligne 188: | Ligne 189: | ||
| next(reader) | next(reader) | ||
| </ | </ | ||
| + | |||
| + | |||
| + | === Lire l' | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | <code python> | ||
| + | import sys | ||
| + | |||
| + | |||
| + | f = open(sys.argv[1]) if len(sys.argv) == 2 else sys.stdin | ||
| + | |||
| + | # ... work with f ... | ||
| + | |||
| + | if len(sys.argv) == 2: | ||
| + | f.close() | ||
| + | </ | ||
| + | |||
| ==== Ecrire sur stderr ==== | ==== Ecrire sur stderr ==== | ||
| + | |||
| + | * [[https:// | ||
| <code python> | <code python> | ||
| Ligne 281: | Ligne 302: | ||
| === Formatage de chaînes de caractères === | === Formatage de chaînes de caractères === | ||
| - | [[https:// | + | [[https:// |
| Il faut doubler les accolades pour qu' | Il faut doubler les accolades pour qu' | ||
| Ligne 374: | Ligne 395: | ||
| </ | </ | ||
| + | |||
| + | === Connaître la langue d'un texte === | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | L' | ||
| + | <code bash> | ||
| + | pip install numpy six icu | ||
| + | pip install pyicu | ||
| + | pip install pycld2 | ||
| + | pip install morfessor | ||
| + | </ | ||
| + | <code python> | ||
| + | from polyglot.text import Text | ||
| + | if Text(txt).language.code not in [" | ||
| + | printf(" | ||
| + | </ | ||
| Ligne 481: | Ligne 519: | ||
| day = int(m.group(1)) | day = int(m.group(1)) | ||
| month = int(m.group(2)) | month = int(m.group(2)) | ||
| + | </ | ||
| + | |||
| + | Trouver toutes les occurrences qui correspondent à un motif ([[https:// | ||
| + | <code python> | ||
| + | re.findall( r'all (.*?) are', 'all cats are smarter than dogs, all dogs are dumber than cats') | ||
| + | # Output: [' | ||
| </ | </ | ||
| Ligne 511: | Ligne 555: | ||
| - | ==== Tester si un flottant est NaN ==== | + | === Tester si un flottant est NaN === |
| <code python> | <code python> | ||
| Ligne 762: | Ligne 806: | ||
| + | ==== Débugguer un segfault ==== | ||
| + | * [[https:// | ||
| + | * https:// | ||
| + | |||
| + | <code bash> | ||
| + | export PYTHONFAULTHANDLER=1 | ||
| + | </ | ||