Python File I/O: Copy the contents of a file to another file
13. Copy File Contents
Write a Python program to copy the contents of a file to another file .
Sample Solution:-
Python Code:
from shutil import copyfile
copyfile('test.py', 'abc.py')
Sample Output:
abc.py
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to copy the contents of one file to another and verify that both files have the same size.
- Write a Python program to copy a file while replacing all occurrences of a specific word during the copy process.
- Write a Python script to duplicate a file and compare the original and copy line by line for equality.
- Write a Python program to copy a file’s contents and then display the first ten lines of the new file.
Go to:
Previous: Write a Python program to write a list content to a file.
Next: Write a Python program to combine each line from first file with the corresponding line in second file.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.