Copy Contents Of One File To Another File In Python
Published on October 28 2021
In this tutorial, you will learn how to read data from a text file and append data to another text file.
ReadData.txt
This is new data. |
WriteData.txt
this is old data.This is new data. |
Source code
file_to_read ="ReadData.txt"
write_to_file="WriteData.txt"
# Reading a file
file = open(file_to_read,"r")
data = file.read()
file.close()
# Writing to a file
with open(write_to_file,"a") as file: # with method auto closes the file object
file.write(data)
print('completed')
Video
Next Tutorial
- Python Program To Create And Write To A Text File
- Python Program To Count Number Of Words In A Text File
- Copy Contents Of One File To Another File In Python
- Python Program To Read A Text File