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 [sample.txt] to be copied to the empty [copy.txt]file.
Using write() function to copy the content from sample.txt to empty file,copy.txt.
Save and run the python program to copy the content.
The text from the sample.txt file is copied to the empty file copy.txt.
Then the text is shown in empty file copy.txt.
#Program to read and copy the content in file
#Developed by:Kishan Shree
#Register No:212223100022
def copy(fname,nfile):
with open(fname,"r") as f:
with open(nfile,"w") as f1:
data1=f.read()
f1.write(data1)
fname=input("Enter an existing file")
nfile=input("Enter a name for new file")
copy(fname,nfile)
Thus the program is written to copy the contents from one file to another file.