有没有一种方法可以将多行文本发送到剪贴板?
我使用了以下命令,但对我不起作用:
import os
text = """sample one \r\n sample two \r\n sample three"""
command = 'echo ' + text.strip() + '| clip'.
os.system(command)
我希望o / p为
sample one
sample two
sample three
解决方法:
import clipboard
clipboard.copy("line1\nline2") # now the clipboard content will be string "line1\nline2"
clipboard.copy("line3") # add line3
text = clipboard.paste() # text will have the content of clipboard
是的,@ Reman说剪贴板复制命令会覆盖它,而不是附加.因此,让我们自己追加.
line = '\n'.join(line, new_line)
clipboard.copy(line)
text = clipboard.paste() # now all lines separated by newline will be on the clipboard.