Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:econchick/new-coder

  • Loading branch information...
commit d4e5053f43110f74655089e2e4f2e6b52f3d8322 2 parents 699b3b4 + 365e478
@econchick econchick authored
View
8 dataviz/full_source/dataviz.py
@@ -19,9 +19,10 @@ def parse(raw_file, delimiter):
"""Parses a raw CSV file to a JSON-like object"""
# Open CSV file, and safely close it when we're done
- with open(raw_file) as opened_file:
- # Read CSV file
- csv_data = csv.reader(opened_file, delimiter=delimiter)
+ opened_file = open(raw_file)
+
+ # Read the CSV data
+ csv_data = csv.reader(opened_file, delimiter=delimiter)
# Setup an empty list
parsed_data = []
@@ -39,7 +40,6 @@ def parse(raw_file, delimiter):
return parsed_data
-
def visualize_days(data_file):
"""Visualize data by day of week"""
View
7 dataviz/tutorial_source/graph.py
@@ -22,9 +22,10 @@ def parse(raw_file, delimiter):
"""Parses a raw CSV file to a JSON-like object"""
# Open CSV file, and safely close it when we're done
- with open(raw_file) as opened_file:
- # Read CSV file
- csv_data = csv.reader(opened_file, delimiter=delimiter)
+ opened_file = open(raw_file)
+
+ # Read the CSV data
+ csv_data = csv.reader(opened_file, delimiter=delimiter)
# Setup an empty list
parsed_data = []
View
7 dataviz/tutorial_source/parse.py
@@ -22,9 +22,10 @@ def parse(raw_file, delimiter):
"""Parses a raw CSV file to a JSON-like object"""
# Open CSV file, and safely close it when we're done
- with open(raw_file) as opened_file:
- # Read CSV file
- csv_data = csv.reader(opened_file, delimiter=delimiter)
+ opened_file = open(raw_file)
+
+ # Read the CSV data
+ csv_data = csv.reader(opened_file, delimiter=delimiter)
# Setup an empty list
parsed_data = []
View
21 docs/_posts/2013-01-04-Part-1-Parse.md
@@ -113,14 +113,16 @@ Just to quickly put these two lines in our `parse` function:
def parse(raw_file, delimiter):
"""Parses a raw CSV file to a JSON-line object"""
- # Open CSV file, and safely close it when we're done
- with open(raw_file) as opened_file:
+ # Open CSV file
+ open_file = open(raw_file)
- # Read CSV file
- csv_data = csv.reader(opened_file, delimiter=delimiter)
+ # Read the CSV data
+ csv_data = csv.reader(opened_file, delimiter=delimiter)
# Build a data structure to return parsed_data
+ # Close the CSV file
+
return parsed_data
```
@@ -159,11 +161,11 @@ Now let’s put the function together:
def parse(raw_file, delimiter):
"""Parses a raw CSV file to a JSON-like object"""
- # Open CSV file, and safely close it when we're done
- with open(raw_file) as opened_file:
+ # Open CSV file
+ opened_file = open(raw_file)
- # Read CSV file
- csv_data = csv.reader(opened_file, delimiter=delimiter)
+ # Read the CSV data
+ csv_data = csv.reader(opened_file, delimiter=delimiter)
# Setup an empty list
parsed_data = []
@@ -175,6 +177,9 @@ def parse(raw_file, delimiter):
for row in csv_data:
parsed_data.append(dict(zip(fields, row)))
+ # Close the CSV file
+ opened_file.close()
+
return parsed_data
```
Please sign in to comment.
Something went wrong with that request. Please try again.