[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A limit to writing to a file from a loop?


On 13/02/19 7:56 AM, Steve wrote:
> My program reads from a text file (A), modifies the data, and writes to another file (B).
> This works until I reach about 300 writes and no more lines are written to file (B).
> I had to create a Counter and increment it to 250 when it gets reset.
> Upon reset, I close the file (B) being written and reopen it for append.
> Then it accepts the entire list of lines of data.
> Bizarre?
>              CycleCounter += 1
>              if CycleCounter > 250:
>                CycleCounter = 1
>                DateReadings.close()
>                DateReadings=open("Date-ReadingsAndDoses.txt", "a")
>                DateReadings.write("{0:15} {1:>8} {2:>8} {3:>8} {4:<2} {5:>8} {6:>8} {7:>10}".format
>                                (ThisTimeDate, ThisReading, ThisDose1, ThisSensor, ThisTrend,
>                                 ThisTS, ThisPercent, SensorNumberDay2) + "\n")

Perhaps part of the transfer to email, but won't this code only output 
once per 250 records, cf 250 records per cycle?

Some suggestions:-

Test one: Prove that there is valid input
- is the code successfully reading more than '250' records?

Test two: Check the actual data
- is there anything strange about the '250th' record (the one that first 
exhibits the problem)?

Test three: Prove that it is not some Python<->file system issue
- what happens if the first input record is written (to a 'junk file') 
250+ times?

Test four: (possibly unnecessary after the above) Disprove a size issue
- what happens if you output a simple/hello world string (of the same 
number of bytes) instead of the incoming data, 250+ times?

Report back. If there are still problems, please show the original code 
and exception report...

Regards =dn