Skip to content

Commit

Permalink
Properly open and close the geojson and csv files
Browse files Browse the repository at this point in the history
  • Loading branch information
guyfawcus committed Nov 3, 2017
1 parent 6dc13e0 commit 55b91da
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions archmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ def make_geojson(parsed_users, output_file):
# Make 'geojson_str' for output.
geojson_str = (dumps(FeatureCollection(geojson), sort_keys=True, indent=4)) + '\n'

output = open(output_file, 'w')
output.write(geojson_str)
output.close()
with open(output_file, 'w') as output:
output.write(geojson_str)


def make_kml(parsed_users, output_file):
Expand Down Expand Up @@ -212,15 +211,13 @@ def make_csv(parsed_users, output_file):
parsed_users (list): A list of lists, each sub_list should have 4 elements: ``[latitude, longitude, name, comment]``
output_file (open): Location to save the CSV output
"""
csvfile = open(output_file, 'w', newline='')
csvwriter = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL)

log.info('Making and writing CSV to ' + output_file)
csvwriter.writerow(['Latitude', 'Longitude', 'Name', 'Comment'])
for user in parsed_users:
csvwriter.writerow(user)
with open(output_file, 'w', newline='') as output:
csvwriter = csv.writer(output, quoting=csv.QUOTE_MINIMAL)

csvfile.close()
log.info('Making and writing CSV to ' + output_file)
csvwriter.writerow(['Latitude', 'Longitude', 'Name', 'Comment'])
for user in parsed_users:
csvwriter.writerow(user)


def main():
Expand Down

0 comments on commit 55b91da

Please sign in to comment.