Copy to system clipboard

Hi Rob,

Redirection of stdout won’t help. Although it is an interesting idea… untested, something like this might work.


# Untested.

class MagicClipboard:
    # A partial implementation of the file interface.

    def write(self, text):
        pyperclip.copy(text)
        return len(text)

    def read(self, num=-1):
        text = pyperclip.paste()
        return text

sys.stdout = MagicClipboard()

This is not a full implementation of the file interface, but it should give you a place to start.

But having said that, it is surely just as simple to call pyperclip.copy() as it is to call print().

And like many simple things, print() disguises a fair chunk of complexity behind a simple interface. It is nearly 70 lines of C.