csvfile.csv
Mr. A,1,Month
Mr. B,2,fire
Mr. C,3,water
main.py
import csv
#Read the file
csv_file = open("csvfile.csv", "r", encoding="utf-8", errors="", newline="" )
print(type(csv_file))
"""
<class '_io.TextIOWrapper'>
"""
#Parses the CSV string.
csvData = csv.reader(csv_file, delimiter=",", doublequote=True, lineterminator="\r\n", quotechar='"', skipinitialspace=True)
print(type(csvData))
"""
<class '_csv.reader'>
"""
#_csv.Convert reader type to list
csvData = [row for row in csvData]
print(type(csvData))
print(csvData)
"""
<class 'list'>
[['Mr. A', '1', 'Month'], ['Mr. B', '2', 'fire'], ['Mr. C', '3', 'water']]
"""
Recommended Posts