python:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
python:accueil [2024/03/07 11:33] – [Chaînes de caractères] add how to determine language of a text phswpython:accueil [2025/09/04 09:32] (Version actuelle) – [Chaînes de caractères] add link phsw
Ligne 189: Ligne 189:
 next(reader) next(reader)
 </code> </code>
 +
 +
 +=== Lire l'entrée standard ou un fichier ===
 +
 +[[https://stackoverflow.com/questions/1450393/how-do-i-read-from-stdin|Source]]
 +
 +<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()
 +</code>
 +
  
  
  
 ==== Ecrire sur stderr ==== ==== Ecrire sur stderr ====
 +
 +  * [[https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/|Redirecting all kinds of stdout in Python]]
  
 <code python> <code python>
Ligne 282: Ligne 302:
 === Formatage de chaînes de caractères === === Formatage de chaînes de caractères ===
  
-[[https://pyformat.info/]]+[[https://pyformat.info/]], [[https://fstring.help/cheat/]]
  
 Il faut doubler les accolades pour qu'elles soient ignorées par Python: Il faut doubler les accolades pour qu'elles soient ignorées par Python:
Ligne 384: Ligne 404:
 pip install numpy six icu pip install numpy six icu
 pip install pyicu pip install pyicu
-pip install pucld2+pip install pycld2
 pip install morfessor pip install morfessor
 </code> </code>
Ligne 499: Ligne 519:
     day = int(m.group(1))     day = int(m.group(1))
     month = int(m.group(2))     month = int(m.group(2))
 +</code>
 +
 +Trouver toutes les occurrences qui correspondent à un motif ([[https://stackoverflow.com/questions/4697882/how-can-i-find-all-matches-to-a-regular-expression-in-python|source]]) :
 +<code python>
 +re.findall( r'all (.*?) are', 'all cats are smarter than dogs, all dogs are dumber than cats')
 +# Output: ['cats', 'dogs']
 </code> </code>
  
Ligne 780: Ligne 806:
  
  
 +==== Débugguer un segfault ====
  
 +  * [[https://stackoverflow.com/questions/16731115/how-to-debug-a-python-segmentation-fault]]
 +  * https://docs.python.org/3/library/faulthandler.html
 +
 +<code bash>
 +export PYTHONFAULTHANDLER=1
 +</code>
  
  • python/accueil.1709807584.txt.gz
  • Dernière modification : 2024/03/07 11:33
  • de phsw