teams_csv.py
import csv
csvfile = open('teams.csv')
reader = csv.DictReader(csvfile)
for each in reader:
print(each["player"])
.py
teams.csv
team,player,goals
Manchester United,George Best,138
Arsenal,Thierry Henry,175
.csv
Note - the windows above contain a CSV file (teams.csv) and a Python script that can parse this teams.csv file.
Ensure both files are saved in the
same folder location.
CSV stands for comma-separated values.
That's because the values are separated with commas.
The first line in a CSV file is (usually) a header row, containing column headings for the records.
Note: a header row is not a requirement of CSV files.
CSV files aren't
hierarchical (unlike XML and JSON), meaning it is difficult to show parent / child organisational patterns in data with CSV.
An
OrderedDict
is a dictionary in Python that preserves the order in which the elements were inserted.