Open In App

Pyperclip module in Python

Improve
Improve
Like Article
Like
Save
Share
Report

Pyperclip is a cross-platform Python module for copy and paste clipboard functions. It works with both Python 2 and 3. This module was created to enable cross-platform copy-pasting in Python which was earlier absent. The pyperclip module has copy() and paste() functions that can send text to and receive text from your computer’s clipboard. Sending the output of your program to the clipboard will make it easy to paste it on an email, word processor, or some other software.

Installing pyperclip:

pip install pyperclip

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

Code 1:




# importing the library
import pyperclip as pc
  
text1 = "GeeksforGeeks"
  
# copying text to clipboard
pc.copy(text1)
  
# pasting the text from clipboard
text2 = pc.paste()
  
print(text2)


Output :

GeeksforGeeks

Code 2:




# importing the library
import pyperclip as pc
  
number = 100
  
# copying text to clipboard
pc.copy(number)
  
# pasting the text from clipboard
text = pc.paste()
  
print(text)
print(type(text))


Output :

100

Note : Copy function will convert every data type to string.


Last Updated : 27 Feb, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads