How to Copy Text to Clipboard in Python

To copy text to the clipboard in Python, use the pyperclip module.

Before you can use the module, you need to install it with:

pip install pyperclip

Then you can use its copy() method to copy text to the clipboard by:

import pyperclip

s1 = "Hello world"


s2 = pyperclip.paste()



Hello world


Thanks for reading. I hope you found what you were looking for.

Happy coding!

Further Reading

Python Tricks

How to Write to a File in Python

The with Statement in Python