How to Copy a File using Python

In this tutorial, you will learn how to copy a file using Python.

TLDR solution

copy.py
import shutil

source = "path-to-file/file_name.extension"
target = "target-path/file_name.extension"

shutil.copyfile(source, target)

Example

Let's say you have a fish.csv file on your desktop and you want to copy it into an existing folder on your desktop named Test. The following Python code will achieve this:

copy.py
import os
import shutil

desktop_path = os.path.expanduser("~/Desktop")

source = desktop_path + '/fish.csv'
target = desktop_path + '/Test/fish.csv'

shutil.copyfile(source, target)

After you run this script (python copy.py), you will find a fish.csv file in the Test folder.