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.

Pyperclip

Install the pyperclip using pip: https://pypi.org/project/pyperclip/

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
pyperclip.paste()

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

Ad: Are you a blogger? Join our Blogging forum.




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


© https://www.includehelp.com some rights reserved.