File copy in python

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

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.


Tech Events

Hackathon