0

I am running my script which increments a variable by writing out a number and reading it back in. Therefor i am creating a txt file that holds the current run number.

f = open("test.txt", "r") x = int(f.readlines()[0]) #assume thet text contains one line with number 1 f.close() f = open("test.txt", "w") x += 1 f.write(str(x)) 

Is there any harm of doing it like that?

1
  • If there is harm belongs to what the other part of your program does - IMHO this is a reasonable approach. Commented May 6, 2016 at 8:25

1 Answer 1

1

Assuming no one ever modifies your text file, and it's not being used for any mission critical applications, I guess there is no harm in doing it this way.

I wouldn't run a nuclear reactor off this set up though. Perhaps as your application progresses you can look into creating a DB to store details like this, which your application can talk to when it needs, then you will have access to more advanced features like security, backups, and functionality for storing and retrieving different types of data for many more purposes.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.