To write a python program for copying the contents from one file to another file.
PC Anaconda - Python 3.7
First we need to open the required the from which we need to copy the text.
Using keyword "with" to open the required file
Again using the with keyword to open the empty file
The empty file is open by using 'W' which is used to write only.
The for function is used to take each line from the main file.
Write() is used to write the lines of main file to the empty file or to the directed file.
#Developed by: Abishai K C
#Register NUmber: 23001564
f = open("C:\\User\\abish\\Desktop\\sample\\Hello world.txt","r")
d1 = f.read()
f2 = open("copy_file.txt","w+")
f2.write(d1)
f2.seek(0)
d2 = f2.read()
print(d2)
f.close()
f2.close()
Thus the program is written to copy the contents from one file to another file.