I am trying to write a response from a Solr server in a CSV file. Im pretty new to python and got the code to change. The code initially looked like this ...
for doc in response.results: status = json.loads(doc['status'])
The script runs and prints the correct information. But it is only everyone who prints one result (the last). I think this is because the loop is constantly writing over the changed status until it processes the response.
After some reading, I decided to keep the information in a list. That way I could print the information to highlight the lines in the list. I created an empty list and changed the code below -
for doc in response.results: list.append = json.loads(doc['status'])
I got this answer after trying to run the code -
`AttributeError: 'list' object attribute 'append' is read-only`.
Where am I mistaken? Is a list not the best approach?
source share