如何将一个字符串复制到Windows剪贴板? python 3 [英] how can I copy a string to the windows clipboard? python 3
本文介绍了如何将一个字符串复制到Windows剪贴板? python 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个变量var ='这是一个变量
如何复制这个字符串到windows剪贴板,所以我可以简单地Ctrl + v,转移到其他地方?
谢谢!
div class =h2_lin>解决方案您可以这样做:
>> ; import subprocess
>>>> def copy2clip(txt):
... cmd ='echo'+ txt.strip()+'| clip'
... return subprocess.check_call(cmd,shell = True)
...
>>>> copy2clip('now this is on my clipboard')
If I have a variable var = 'this is a variable'
how can I copy this string to the windows clipboard so I can simply Ctrl+v and it's transferred elsewhere? I don't want to use anything that isn't that isn't built in, I hope it's possible.
thanks!
解决方案
You can do this:
>>> import subprocess
>>> def copy2clip(txt):
... cmd='echo '+txt.strip()+'|clip'
... return subprocess.check_call(cmd, shell=True)
...
>>> copy2clip('now this is on my clipboard')
这篇关于如何将一个字符串复制到Windows剪贴板? python 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文