如何将多行传递到剪贴板?

有没有一种方法可以将多行文本发送到剪贴板?

我使用了以下命令,但对我不起作用:

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

解决方法:

使用clipboard module

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.
上一篇:【原创】大叔经验分享(33)hive select count为0


下一篇:剪贴板更新事件被多次触发