Resolved: Just needed help in knowing how to edit a file already written and closed
How to edit the contents of the file already written and closed?
Thank you for reaching out!
Please, refer to the following thread which might answer your question:
Let me know if something remains unclear.
Thank you for your response. I understood the append function. I wanted to know if we can edit and change the names of the content already in the file. Like in the example you provided, can we edit the text Line 1 and Line 2?
Thank you for clarifying.
You can do this, for example, in the following way:
1. First, open (or create) a file in 'write' mode and write some text inside.
2. Then, open the file again, this time in read mode. Use the replace() function to first specify the text you want to replace (in this case, 'Line') and then the text that would replace it (in this case, 'Row'). The variable
to_replace is a string containing the updated text from the sample.txt file.
3. Finally, open the file in 'write' mode and write the content stored in the
Hope this helps!