Automatically Copy the Output of a Python Program Easily

A guide on how to automatically copy the output of a Python program into a clipboard.

Handhika Yanuar Pratama
Python in Plain English

--

Photo by Surface on Unsplash

Sometimes we need to directly copy the output from the program that we created. Did you know Python has a library that helps us do this thing? It is called pyperclip. Pyperclip was created in 2013 and updated on 21 February 2021 with version 1.8.2. This module is a cross-platform Python module for copy and pasting clipboard functions and works on both versions of Python.

Installation

For starters, run this script to install pyperclip.

pip install pyperclip

You can read the full documentation here.

Example

For example, I would like to create a simple program for securing URL format. It will simply replace all ‘.’ and ‘:’ Into ‘[.]’ and ‘[:]’; This program is used to save anyone from doing false clicking into a link that could lead to some phishing site.

Well, it is just for example, so after running the script, you will be asked to put some URL here, then the output will come out, and it will copy the output into your clipboard, like this.

Tadaaa, right now, you could click ctrl+V, and Bob is your uncle.

Conclusion

In this story, I talk about how to automatically copy the output of a Python program into a clipboard, you can implement it whenever you want. Let’s improve our daily life by creating a simple program like this. Thanks for reading. ✌️

More content at PlainEnglish.io. Sign up for our free weekly newsletter. Follow us on Twitter and LinkedIn. Join our community Discord.

--

--