Pyperclip module in Python

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :

GeeksforGeeks

Code 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output :

100

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

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.