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" pyperclip.copy(s1) s2 = pyperclip.paste() print(s2)
Output:
Hello world
Conclusion
Thanks for reading. I hope you found what you were looking for.
Happy coding!
Further Reading
How to Write to a File in Python
About the Author
- I'm an entrepreneur and a blogger from Finland. My goal is to make coding and tech easier for you with comprehensive guides and reviews.
Recent Posts
Artificial Intelligence2023.03.14Best AI Tools of 2023 (Save Time & Boost Productivity)
Python2023.02.16How to Pass a Variable from HTML Page to Another (w/ JavaScript)
JavaScript2023.02.16JavaScript How to Get Selected Text from a Textbox
JavaScript2023.02.15JavaScript Select All Text in Div with a Mouse Click