Friday, December 27, 2024
Google search engine
HomeLanguagesPyperclip module in Python

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:




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


Output :

Lazyroar

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.

RELATED ARTICLES

Most Popular

Recent Comments