Exportation
L'extrait de code peut être consulté sans aucune authentification.
Rédigé par
Thomas "Oxymore" Kowalski
Modifié
export.py 593 o
import json
import os
# Notre plan de métro
monPlan = {
"ligne 1" : ["station 1", "station 2", "..."],
"ligne 2" : ["...", "..."]
}
# Si le fichier plan existe
if os.path.isfile("plan.json"):
# On va essayer de le charger
try:
# On ouvre le fichier en lecture
with open("plan.json", 'r') as f:
# On le charge
monPlan = json.load(f)
except:
pass
# Affichage du plan
print("Plan : {}", str(monPlan))
# Ouverture du fichier en écriture
with open("plan.json", "w") as f:
# Ecriture du fichier
json.dump(monPlan, f)
Veuillez vous inscrire ou vous se connecter pour commenter