Writing a CSV file

Hi there,
I wanted to ask whether the order in which we write the fields=[…] matter when writing a csv file?
Here is the example:

access_log = [{‘time’: ‘08:39:37’, ‘limit’: 844404, ‘address’: ‘’}, {‘time’: ‘13:13:35’, ‘limit’: 543871, ‘address’: ‘’}, {‘time’: ‘19:40:45’, ‘limit’: 3021, ‘address’: ‘’}, {‘time’: ‘18:57:16’, ‘limit’: 67031769, ‘address’: ‘’}, {‘time’: ‘21:17:13’, ‘limit’: 9083, ‘address’: ‘’}, {‘time’: ‘23:34:17’, ‘limit’: 65913, ‘address’: ‘’}, {‘time’: ‘13:58:05’, ‘limit’: 1541474, ‘address’: ‘’}, {‘time’: ‘10:52:00’, ‘limit’: 11465607, ‘address’: ‘’}, {‘time’: ‘14:56:12’, ‘limit’: 109, ‘address’: ‘’}, {‘time’: ‘18:56:35’, ‘limit’: 6207, ‘address’: ‘’}]

import csv
with open(“logger.csv”,“w”) as logger_csv:
field =[ “time”, “limit”,“address”] # THIS GIVES ME AN ERROR EVEN THOUGH THE ACCESS_LOG IS IN THIS ORDER!?!?
log_writer = csv.DictWriter(logger_csv, fieldnames=field)
for i in access_log:
======= END OF CODE ==========
THIS LINE -----field =[ “time”, “limit”,“address”] ---- # THIS GIVES ME AN ERROR EVEN THOUGH THE ACCESS_LOG IS IN THIS ORDER??? BUT, fields =[‘time’,‘address’,‘limit’] WORKS ??? WHY IS THAT???

Could you please check the following FAQ for details of how to format code for the forums, it’s harder to understand without it.

What error are you receiving from this line?

This is the error that I am receiving: " Did you write the contents of access_log to logger.csv as a CSV?"

Is this part of a lesson, if so please include the link.

That error doesn’t look like it’s anything to do with Python itself and is more likely a background test checking the contents of the file (if the file is in a different order than it expected then the test may be failing).