How to copy files
To copy a file in Python, you can use the built-in "shutil" module. Here is an example of how to copy a file:
import shutil
# Copy the file "original.txt" to "copy.txt"
shutil.copy("original.txt", "copy.txt")
Watch a video course
Python - The Practical Guide
You can also use the "os" module to copy files in Python. Here is an example of how to do that:
import os
# Open the original file and the copy file in read and write mode
with open("original.txt", "r") as original_file, open("copy.txt", "w") as copy_file:
# Read the contents of the original file
contents = original_file.read()
# Write the contents to the copy file
copy_file.write(contents)
Both of these methods will create a new file called "copy.txt" that is a copy of the original file "original.txt".