[英]Copy text with newlines to clipboard :Python
I want to copy text with newlines to the clipboard using the following code. 我想使用以下代码将带有换行符的文本复制到剪贴板。
import pyperclip
numbers=''
for i in range(200):
numbers = numbers + str(i) + '\n'
pyperclip.copy(numbers)
After execution the clipboard should contain: 执行后,剪贴板应包含:
0
1
2
.
.
200
But after I run the program and paste in Notepad. 但是在我运行程序并粘贴在记事本中之后。 I see 我懂了
012345....200
All in a single line. 全部在一行中。 :( I use Python 3.6.1 on Windows 10 :(我在Windows 10上使用Python 3.6.1
I assume you're pasting into microsoft notepad. 我假设您要粘贴到Microsoft记事本中。 In this case you should use \\r\\n
(windows style) instead of \\n
only (unix style) 在这种情况下,您应该使用\\r\\n
(Windows样式)而不是仅\\n
(unix样式)
If you paste into notepad++ it will treat the newline character unix style, and you will see it separated like you want. 如果将其粘贴到notepad ++中 ,它将处理换行符unix样式,并且您会看到将其分隔为所需的样式。
If you want to be OS independent then use os.linesep
如果要独立于操作系统,请使用os.linesep
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.