To write a python program for copying the contents from one file to another file.
PC Anaconda - Python 3.7
Start the program
Open the file f1 in read mode
Open the file f2 in write mode
Copy the contents using write() with the for loop
End the program
#Python program to copying the contents from one file to another file.
#Developed by: THEJASWINI
#Reference number: 212223110059
def copy(fname,newfile):
with open(fname,'r')as fp:
with open(newfile,'w')as fp1:
data1=fp.read()
fp1.write(data1)
fname=input("Enter an existing file: ")
newfile=input("Enter a name for new file: ")
copy(fname,newfile)
Thus the program is written to copy the contents from one file to another file.