This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
python_cheatsheet [2019/08/25 20:01] nasikimi |
python_cheatsheet [2020/04/02 17:19] (current) nasikimi |
||
---|---|---|---|
Line 8: | Line 8: | ||
===== Snippets ===== | ===== Snippets ===== | ||
+ | |||
+ | === Une version du find === | ||
+ | <code python> | ||
+ | import os | ||
+ | |||
+ | path = 'c:\\projects\\hc2\\' | ||
+ | |||
+ | files = [] | ||
+ | # r=root, d=directories, f = files | ||
+ | for r, d, f in os.walk(path): | ||
+ | for file in f: | ||
+ | if '.txt' in file: | ||
+ | files.append(os.path.join(r, file)) | ||
+ | |||
+ | for f in files: | ||
+ | print(f) | ||
+ | </code> | ||
=== Retourner les lignes non-vides d'un fichier === | === Retourner les lignes non-vides d'un fichier === |