Python Pyperclip – Copy CSV data to clipboard

In this post we will be creating a Python script that will copy the contents of a CSV file to the clipboard. To do this we will use the Pyperclip module which enables us to copy and paste clipboard functions.

See the sample of Python code below where we copy the data within our CSV file to the clipboard using the Pyperclip library. We start by opening the CSV and reading the data within, we then add a separation comma for each row of data found before copying this to our clipboard.

import pyperclip
import csv

with open('Spreadsheet.csv', 'r') as file:
    csv_reader = csv.reader(file)
    csv_data = "\n".join([",".join(row) for row in csv_reader])

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply