Alex Ramadan Alex Ramadan - 2 years ago 154
Python Question

Copying the contents of a variable to the clipboard

I am trying to copy the contents of a variable to the clipboard automatically within a python script. So, a variable is created that holds a string, and I'd like to copy that string to the clipboard.

Is there a way to do this with Pyclips or

os.system("echo '' | pbcopy")

I've tried passing the variable where the string should go, but that doesn't work which makes sense to me.

Answer Source

Have you tried this?

import os
def addToClipBoard(text):
    command = 'echo ' + text.strip() + '| clip'

Read more solutions here.


You may call it as:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download