To write a python program for copying the contents from one file to another file.
PC Anaconda - Python 3.7
Open fname (the file whose contents need to be copied).
Open newfile (the file to be pasted in).
Read the text from the contents need to be copied.
Write the text into the other file.
Get the input from the user
Print the output.
#Developed by: Thaksha Rishi
#Register Number: 212223100058
def copy(fname,newfile):
with open(fname,'r') as fp, open(newfile,'w') as fp1:
data=fp.read()
fp1.write(data)
fname=input("Enter an existing file: ")
newfile=input("Enter a name for the new file: ")
copy(fname,newfile)
Thus the program is written to copy the contents from one file to another file.