Semaine 4, jour 2
This commit is contained in:
42
Semaine_04/Fonctions/functions.py
Normal file
42
Semaine_04/Fonctions/functions.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
from tkinter.ttk import Separator
|
||||
import pandas
|
||||
import csv
|
||||
|
||||
def addition(a: int, b: int):
|
||||
somme = a + b
|
||||
return somme
|
||||
|
||||
def create_folder(path: str, name:str):
|
||||
chemin_complet = os.path.join(path, name)
|
||||
if not os.path.isdir(chemin_complet):
|
||||
os.mkdir(chemin_complet)
|
||||
|
||||
def create_empty_csv_file(
|
||||
path: str,
|
||||
filename: str,
|
||||
/, # ce qui est avant le / est du positionnage
|
||||
*, # ce qui est après le * est du nommage
|
||||
colonnes: list,
|
||||
separateur: str = ","
|
||||
):
|
||||
tableau = pandas.DataFrame(columns= colonnes)
|
||||
chemin_complet = os.path.join(path, filename)
|
||||
tableau.to_csv(
|
||||
path_or_buf= chemin_complet,
|
||||
sep= separateur,
|
||||
index= False
|
||||
)
|
||||
|
||||
def write_to_csv(
|
||||
path: str,
|
||||
filename: str,
|
||||
colonnes: list,
|
||||
donnees: list[dict]
|
||||
):
|
||||
if not filename.endswith(".csv"):
|
||||
filename += ".csv"
|
||||
chemin_complet = os.path.join(path, filename)
|
||||
fichier_csv = open(chemin_complet, "a")
|
||||
writer = csv.DictWriter(fichier_csv, colonnes, delimiter= separateur, lineterminator= "\n")
|
||||
writer.writerows(donnees)
|
||||
Reference in New Issue
Block a user