Home » Python

Copy data to clipboard in Python

Example of pyperclip module methods: Here, we are going to learn how to copy data to clipboard in Python?
Submitted by Sapna Deraje Radhakrishna, on October 12, 2019

By copying the data to the clipboard, we can automate the copying of data from a website or any document.

pyperclip, provides a cross-platform python module for copying and pasting the text to the clipboard. Pyperclip is a third party library that needs to be installed in the virtual environment or the anaconda environment using the pip.


Install the pyperclip using pip:

To copy the text to the clipboard, pass a string to pyperclip.copy() and to paste the text from the clipboard, invoke pyperclip.paste() and the copied text will be returned as a string value.

Python code:

#importing the module
import pyperclip

# copies all the data the user has copied
pyperclip.copy('Copy to clipboard')

# paste the copied data from clipboard

Usage of copying the data from clipboard and pasting it

  1. Adding bullet points to wiki markup – get the text from the clipboard, add a star and space to the beginning of each line and then paste the new text to clipboard.
  2. Add a script which retrieves the link from the clipboard, and fetch the metadata for that link, copy the metadata and link back to the clipboard.


Comments and Discussions!





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.