2021年3月9日星期二

How to add an integer variable to a number in a .txt file in Python? [duplicate]

I have a python script that calculates a variety of numbers for me in a loop. For example, in every loop it calculates:

Time:  Number of events:  Number of errors:  

I have created a .txt file to keep track of lifelong statistics. I want the script to add to the text file every time it completes a loop. For example, let's say when I first start the script, the text file looks like:

Time: 60  Number of events: 10  Number of errors: 5  

Now I run the script and in one loop it calculates 30 time, 3 events, and 1 error. I want it to update the text file so that it reads:

Time: 90  Number of events: 13  Number of errors: 6  

Is this possible?

https://stackoverflow.com/questions/66558226/how-to-add-an-integer-variable-to-a-number-in-a-txt-file-in-python March 10, 2021 at 12:06PM

没有评论:

发表评论