Pyperclip not pasting new lines?

a 夏天 提交于 2019-12-24 10:49:55

问题


I'm trying to make a simple script which takes a list of names off the clipboard formatted as "Last, First", then pastes them back as "First Last". I'm using Python 3 and Pyperclip.

Here is the code:

import pyperclip
text = pyperclip.paste()
lines = text.split('\n')
for i in range(len(lines)):
    last, first = lines[i].split(', ')
    lines[i] = first + " " + last
text = '\n'.join(lines) 
pyperclip.copy(text)

When I copy this to the clipboard:

Carter, Bob
Goodall, Jane

Then run the script, it produces: Bob CarterJane Goodall with the names just glued together and no new line. I'm not sure what's screwy.

Thanks for your help.


回答1:


Apparently I need to use '\r\n' instead of just '\n'. I don't know exactly why this is but I found that answer on the internet and it worked.



来源:https://stackoverflow.com/questions/42464388/pyperclip-not-pasting-new-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!