Skip to content
Advertisement

Python: values written to csv file are in reverse order?

Here is the code in question first:

JavaScript

Here is an example output:

JavaScript

Why is the csv being written in reverse? The time stamp should be going from 03:23:08 to 03:23:13, but it’s not.. I’m thinking it’s maybe because I’m calling this recursively? But not totally sure. the ‘a’ in the with open() is for ‘append’, so logically it should just append each value one after the other as they’re returned.

Advertisement

Answer

Unindent the recursive call out of the with open, so that the buffered written row is actually flushed/written to the file before the recursive call instead of after the recursive call returned.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement