To write a python program for copying the contents from one file to another file.
PC Anaconda - Python 3.7
Create two txt file.A file which has content [lines.txt] to be copied to the empty [text.txt]file.
Using write() function to copy the content from line.txt to empty file,text.txt.
Save and run the python program in terminal.
The text from the lines.txt file is copied to the empty file text.txt
Then the text is shown in empty file text.txt.
Result is obtained.
#Developed by : VAISHNAVI S
#RegisterNumber : 22009040
print("Enter the Name of Source File: ")
sFile = input()
print("Enter the Name of Target File: ")
tFile = input()
fileHandle = open(sFile, "r")
texts = fileHandle.readlines()
fileHandle.close()
fileHandle = open(tFile, "w")
for s in texts:
fileHandle.write(s)
fileHandle.close()
print("\nFile Copied Successfully!")
Thus the program is written to copy the contents from one file to another file.