Site Tools


informatique:python

This is an old revision of the document!


Python

Je débute en Python, je jette ici mes notes en vrac. Comme d'habitude j'apprends par la pratique, donc ce n'est pas forcément toujours très propre mais au moins fonctionnel pour mes besoin.

Initialiser un environnement virtuel (venv)

Linux

python3 -m venv ~/undossier
source undossier/bin/activate

Windows

python -m venv undossier
.\undossier\Scripts\activate

Définir une variable

nom_variable = "contenu variable"

Écrire un fichier

f = open(nomfichier.txt, "w")
f.write("blablabla")
f.close

Date et heure

import datetime
# Récupère la date courante
date_now = datetime.datetime.now()
# Formate la date au format AAAA-MM-DD HH:mm
print(date_now.strftime("%Y-%m-%d %H:%M"))
# Pour stocker dans une variable
date = str(date_now.strftime("%Y-%m-%d %H:%M"))
informatique/python.1731920269.txt.gz · Last modified: 2024/11/18 08:57 by yahiko