D
D
Danil Samodurov2020-06-27 14:41:05
Python
Danil Samodurov, 2020-06-27 14:41:05

How to change the mode of working with a file?

The task is as follows: you need to change the data from the file and write it to the same file.
The file is opened like this: How to change the mode of working with a file without repeating the open () instruction. Or, how to open a file for writing after saving the contents to a string variable? open('file.json', 'r')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
15432, 2020-06-27
@samodurOFF

And you can't open it for reading + writing with the 'r +' parameter?
save - do
data = myfile.read()
and then
newfile.write(data)

D
Developer, 2020-06-27
@samodum

No way. You make an intermediate file, write there what you read from the desired file with changes, and then rename the new one to the old one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question