Reading from one file , writing into other file by creating file.
-
How do I read from one file and write into another file by creating that file using python?
I am able to read file but when I write existing file is getting overwritten. I have set of files containing folder so I have to dynamically create file while writing only. But I am not able to do it. Can someone help me? -
@Teju said in Reading from one file , writing into other file by creating file.:
I am able to read file but when I write existing file is getting overwritten
So, do you want to append to the existing file, or what?
Please explain better. -
Hi,
If you want to append new data to an existing file, open it in append mode.
-
@Teju said in Reading from one file , writing into other file by creating file.:
How do I read from one file and write into another file by creating that file using python?
I am able to read file but when I write existing file is getting overwritten.If you want to write to another file do not write to the file you have read from.
If the other file exists and you tell it to overwrite it, it will overwrite it.
If the other file exists and you want to append to it, open it for append. -
@JonB i do not understand how to create new file in the middle of the task and copy everything inside existing file to new file by replacing only single line.
I have to create the file through code,
Ex if existing file which I am reading is ex.py then new file has to be ex_1.py(having everything exactly same as ex.py except one line)