{{tag>dev python fichier file}}
====== Manipulation des fichiers en python ======
Pour manipuler aisém... en fonction de l'encodage choisit:
<code python>
file = open('/path/to/file.txt', 'w', encoding='utf8')
for cpt in range(100):
file.write(f"ligne {cpt:4d}\n")
# l'appel de la méth
puis lequel il a été importé via l'attribut ''%%__file__%%'' :
<code python>
import mod
mod.__file__
</code>
===== L'instruction import =====
Le contenu d'... Foo', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__',
'__name__', '__package__', '__s... n affichage :
<code bash>
python mod.py
</code>
<file>
If Comrade Napoleon says it, it must be right.
[
la façon dont une valeur doît être représentée:
<file>
f"foo {expression:.2f} bar"
</file>
Ici la f-string comporte une expression à gauche du caractère**':'...
>>> filenames = ['file01.txt', 'file02.log', 'file-03.txt']
>>> print(re.ma
ommande retourne quelques messages de la forme :
<file>
INFO [alembic.runtime.migration] Context impl S... 681708867_initial_db_model_product.py ... done
</file>
L'outil analyse les modifications apportées au ... La commande retourne quelques messages du type :
<file>
INFO [alembic.runtime.migration] Context impl S... rade -> a09681708867, Initial DB Model Product
</file>
Si on inspecte à nouveau la base, on peut voir
Ajouter un fichier .env à la racine du projet :
<file txt .env>
# Environnement
# Paquetage flask
FLASK_APP="gcomp"
</file>
<note>
Pour que les fichiers .env soient chargé... tivate'' de l'environnement virtuel du projet :
<file txt [highlight_lines_extra="7"] >
...
48
49 _... ort PATH
52
53 export FLASK_APP="gcomp"
...
</file>
Éditer également la fonction ''deactivate'' en
fts3_tokenizer on
legacy_alter_table off
legacy_file_format off
load_extension on
no_ckpt_on_c... e, on obtient le comportement attendu !
</note>
<file txt [highlight_lines_extra="4"]>
sqlite> .dbconfi... ntime error: FOREIGN KEY constraint failed (19)
</file>
C'est bien une variable de configuration pour n... ion.commit()
Traceback (most recent call last):
File "/home/yoann/dev/poc/categories/.venv/lib/python3
début de fichier:
<code>
python mon_script.py
File "mon_script.py", line 2
SyntaxError: encoding pro... a forme suivante est retournée par interpréteur:
<file>
UnicodeEncodeError: 'charmap' codec can't encode... ' in position 54: character maps to <undefined>
</file>
Le caractère u'\ufeff ' est le BOM((**B**yte **... rture du fichier:
<code python>
with open("data/file.txt", "r", encoding='utf-8-sig') as fp:
</code>
e** attention au nombre de caractères obliques:
<file>
# Base temporaire stockée en mémoire RAM
sqlite:... n relatif vers la base
sqlite:///relative/path/to/file.db
# Chemin absolu vers la base
sqlite:////absolute/path/to/file.db
</file>
===== Références =====
* http://www.pythoncentral.io/introductory-tutorial-python-sqlalc
{{tag>dev python flask web upload download file fichier}}
====== Flask : Upload/Download de fichiers =... ps://flask.palletsprojects.com/en/stable/patterns/fileuploads/|Téléverser des fichiers avec Flask (docum... sk)]]
* [[https://pythonbasics.org/flask-upload-file/|Téléversement d'un fichier avec Flask (pythonbasics.org)]]
* [[https://pythongeeks.org/flask-file-uploading/|Uploding de fichier via Flask (pythong
tion en s'alignant sous les paramètres.
</note>
<file txt hello.rst>
Hello World
===========
Hello Sphinx !!!
</file>
Le fichier index.rst contient le sommaire génér... == Liens externes ====
Pour une URL (externe) :
<file>
Syntaxe d'écrite d'une URL `mon titre <https://example.com>`_
</file>
<note warning>
* Attention aux guillemets arr
d prints the spreadsheet's header columns
:param file_loc: The file location of the spreadsheet
:type file_loc: str
:param print_cols: A flag used to print the columns to