diff --git a/dataviz/full_source/dataviz.py b/dataviz/full_source/dataviz.py index 318329eb..56aec4f8 100644 --- a/dataviz/full_source/dataviz.py +++ b/dataviz/full_source/dataviz.py @@ -28,7 +28,7 @@ def parse(raw_file, delimiter): parsed_data = [] # Skip over the first line of the file for the headers - fields = csv_data.next() + fields = next(csv_data) # Iterate over each row of the csv file, zip together field -> value for row in csv_data: diff --git a/dataviz/tutorial_source/graph.py b/dataviz/tutorial_source/graph.py index aca9908c..b32e1764 100755 --- a/dataviz/tutorial_source/graph.py +++ b/dataviz/tutorial_source/graph.py @@ -31,7 +31,7 @@ def parse(raw_file, delimiter): parsed_data = [] # Skip over the first line of the file for the headers - fields = csv_data.next() + fields = next(csv_data) # Iterate over each row of the csv file, zip together field -> value for row in csv_data: diff --git a/dataviz/tutorial_source/parse.py b/dataviz/tutorial_source/parse.py index 1a757db0..0054fa8e 100644 --- a/dataviz/tutorial_source/parse.py +++ b/dataviz/tutorial_source/parse.py @@ -23,7 +23,7 @@ def parse(raw_file, delimiter): # Open CSV file, and safely close it when we're done opened_file = open(raw_file) - + # Read the CSV data csv_data = csv.reader(opened_file, delimiter=delimiter) @@ -31,7 +31,7 @@ def parse(raw_file, delimiter): parsed_data = [] # Skip over the first line of the file for the headers - fields = csv_data.next() + fields = next(csv_data) # Iterate over each row of the csv file, zip together field -> value for row in csv_data: @@ -48,7 +48,7 @@ def main(): new_data = parse(MY_FILE, ",") # Let's see what the data looks like! - print new_data + print(new_data) if __name__ == "__main__": diff --git a/website/_containers/dataviz/2013-01-04-part-1.md b/website/_containers/dataviz/2013-01-04-part-1.md index f51a2628..c5b30578 100644 --- a/website/_containers/dataviz/2013-01-04-part-1.md +++ b/website/_containers/dataviz/2013-01-04-part-1.md @@ -153,13 +153,13 @@ parsed_data = [] Good — we have a good data structure to add to. Now let’s first address our column headers that came with the CSV file. They will be the first row, and we’ll assign them to the variable `fields`: ```python -fields = csv_data.next() +fields = next(csv_data) ```
.next
method on csv_data
because it is a generator. We just call .next
once, since headers are in the 1st and only row of our CSV file.
+We were able to use next(csv_data)
because csv_data
is a generator. We just call next(csv_data)
once, since headers are in the 1st and only row of our CSV file.