csvfile.csv
Monsieur A,1,Mois
Monsieur B,2,Feu
Monsieur C,3,eau
main.py
import csv
#Lisez le dossier
csv_file = open("csvfile.csv", "r", encoding="utf-8", errors="", newline="" )
print(type(csv_file))
"""
<class '_io.TextIOWrapper'>
"""
#Analyse la chaîne CSV.
csvData = csv.reader(csv_file, delimiter=",", doublequote=True, lineterminator="\r\n", quotechar='"', skipinitialspace=True)
print(type(csvData))
"""
<class '_csv.reader'>
"""
#_csv.Convertir le type de lecteur en liste
csvData = [row for row in csvData]
print(type(csvData))
print(csvData)
"""
<class 'list'>
[['Monsieur A', '1', 'Mois'], ['Monsieur B', '2', 'Feu'], ['Monsieur C', '3', 'eau']]
"""
Recommended Posts