Has anyone ever repeatedly wrote to the same text file, using the append mode, and when examining the text file, several lines were missing?
Here are the specifics to my code:
Each line in the output, the text file, contains data from one experimental session (e.g. the session time, experimenter name, session #, a series of responses to variables being tested)
When I first write to the text file, I create a string variable that starts with "\n". Here's an example of the code:
sessioninfo = "\n" + "," + string_variables + "," fp=open("data.txt", "a") fp.write(sessioninfo) fp.close()
During the course of the experiment, the program opens the text file and writes more information (e.g. the study variables). Here's an example below:
dependent_variables = string_varaibles + ","
The last time I write to the file (for each experimental session) the code looks just like #3.
During cleaning and creation of the data base, I noticed that there are missing lines in the data file. Could my program have written over a line in the "data.txt"? Could the program start writing to the text file at a point that is not the true end? (Thus resulting in overwriting.)
I only have whole lines of data missing. There are no lines where the file was written to in the middle of a line.
Also, I understand that the append mode should start at the end to begin writing. The other options to use with the open command, which I don’t use, could any of those be the cause? Basically, I need to know if my program could potentially do this again?
I have already figured out alternatives to my original program, but would still like to know why this happened.
Any and all feedback is appreciated. I am not a programmer by trade, so please take that into consideration when responding (i.e. keep it as simple as you can).