File copy in python

Python Program to Copy the contents of one file to another file

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

Program or Solution

				
			
					
file1=open("sample.txt",'r')
file2=open("sample1.txt",'w')
content=file1.read()
file2.write(content)
file1.close()
file2.close()

			
				
			

Program Explanation

open the source file file1 in read mode open the destination file file2 in write mode read the contents of file1 and store it in variable content.

Write content into file2, then close both the files file1 and file2.

Comments


Related Programs