Created
October 27, 2022 17:57
-
-
Save khornberg/2830e73018e9d9176e2af2ba4a31eff3 to your computer and use it in GitHub Desktop.
Reading a CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
More documenation about the csv moodule at https://docs.python.org/3/library/csv.html | |
""" | |
import csv | |
# the path to the file is relative to where you execute the python command | |
# both this file and the test.csv file should be in the same directory/folder | |
# you should run the command `python example.py` (without the backticks `) from the directory that contains example.py | |
with open('test.csv') as csvfile: | |
row_reader = csv.reader(csvfile) | |
# row_reader reads each row of your csv file | |
for row in row_reader: | |
print(row) | |
""" | |
Outputs | |
['col-a', 'col-b'] | |
['value-a', 'value-b'] | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
col-a | col-b | |
---|---|---|
value a | value-b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment