I
I
InternetMaster2021-11-14 12:30:35
Python
InternetMaster, 2021-11-14 12:30:35

How to take a value and add 1 to it in a .txt file?

Task: you need (if there is a file) to take a value from it (it is always a number) and add 1 to it and write it back to the file. In this case, if the file does not exist, then the system should create it and write "1" there by default. How to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-11-14
@InternetMaster

InternetMaster ,
if the file exists - open it, read the number,
convert the number to int, add one
delete the old file
write a file with the same name and increment in its place
if the file does not exist, then create a file and write 1 there , that 's
all
item is problematic?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question