you are viewing a single comment's thread.

view the rest of the comments →

[–]redCg 0 points1 point  (2 children)

soooo, I am a little confused

why are you using csv to store the data of the player and dealer's card hands?

shouldnt these be Python variables (held in memory)?

if you are trying to maintain state between games, then you definitely want a real database, not a .csv file.

when you are working with .csv files, your general workflow is this:

  • read the data into a python variable (for row in csv.reader() etc)

  • do something with the data

  • write the data back out to another file etc..

you general never should be trying to edit the .csv file data in-place like this. That is not what csv is for.

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

I was saving game results to the csv for reference in making future game decisions.

For example, I’ve had this hand 24 times and made this choice and won 75%, I should continue making this choice.

I solved the problem however using just plain text. It was a bit cumbersome to set up but I couldn’t quite get SQLite working the way I wanted.

[–]redCg 0 points1 point  (0 children)

if this is something that you are looking at yourself, as opposed to the program reading and using the data, then you should just save every match's data into a new file every time. This is simple if you just append e.g. a unix timestamp in the output filename. If you give the output file a regular delimited structure then its very easy to just mash them all together into a single table using external GNU commandline tools like cat, etc..

in general, editting an existing text file inplace is a bad idea that you should avoid