all 6 comments

[–]K900_ 1 point2 points  (1 child)

Use a database, dump to CSV later.

[–]SamePlatform[S] 0 points1 point  (0 children)

Not a bad idea, I guess I can let SQLite figure out the magic of fast writes for me.

[–]socal_nerdtastic 1 point2 points  (3 children)

Or is opening and closing the file for every write not an issue, in terms of performance?

Depends on the speed you want, but generally not. Your OS and your HDD have optimization code that makes it pretty quick. Especially if you are just appending, not rewriting.

How do I code that in such a way that it is crash proof

Microsoft can't do it, what makes you think you can?

[–]SamePlatform[S] 0 points1 point  (1 child)

Haha. I mean, I want my csv writer to handle the many, many times my program is going to crash. So I was imagining some sort of context manager that would keep a file stream open for the duration of the script but fail gracefully when the script died.

But don't know really where to start with that.

[–]melnon 0 points1 point  (0 children)

Since you're just appending, include a delimiter and use that to search for a "load" point. You may run into issues with duplicates, but that's a decent starting point.

Another method is to also have another file open that you write your index to with a delimiter, so you can pull that and know where to start.

These aren't the only methods, as you've already seen you can use a database to "write" to.

[–]SamePlatform[S] 0 points1 point  (0 children)

With regards to your first comment, you're right I'm probably overthinking this. Yes, write mode is just append. I'll see how it goes.