Al Sweigart's pyperclip library for Python attempts to provide cross-platform methods for interacting with the clipboard on a computer desktop. I and others have found that the .copy method does not work with our Linux desktops (mine is currently Ubuntu 18.04 LTS with the default Gnome Shell).
A workaround was identified gkotian in an issue opened on the project's Github repo.
Here's the snippet provided by gkotian, which I used in a project from Al's Automate the Boring Stuff with Python book.:
import os
text = 'The text to be copied to the clipboard.'
os.system("echo '{}' | xclip -selection clipboard".format(text))
This workaround requires installation of astrand's xclip program (installed on Ubuntu with "sudo apt install xclip").
Hi !. I've been trying to improve my skills in python by reading and doing the exercises proposed in Al Sweigart's book. I use Debian and there was an issue on the pyperclip module while running the codes for Adding Bullets to Wiki Markup and Password Locker. The solution proposed by gkotian was successfully implemented in both codes and performed as expected. However, I would like to inquire whether it is feasible to have xclip copy the text from the clipboard instead of storing it in a variable, and then perform the modifications and resend it back to the clipboard. Thank you! Luciana.