Windows下利用win32clipboard实现Python的剪切板(Clipboard)操作
2017-08-01 05:50
1466 查看
最近翻译论文的时候发现复制过来的文字经常带有很多的换行符,为了方便的去除这些换行符,写了一个python小方法。
代码如下(适用于Python3):
保存并命名为“stripClipboard.py”。每当从论文里复制了文字后,只需运行
例如,从论文中ctrl+v了如下文字:
运行
注1: 要使用win32clipboard需安装pypiwin32,可用
注2: Mac下Python的剪切板操作将在另一篇文章里介绍
注3(已解决):处理中文字符时会乱码
代码如下(适用于Python3):
import win32clipboard as wc import win32con def stripClipboard(): wc.OpenClipboard() txt = wc.GetClipboardData(win32con.CF_UNICODETEXT) n=0 txt=str(txt).strip() for x in ["\r\n","\n","\r"]: n=n+txt.count(x) txt=txt.replace(x,'') wc.EmptyClipboard() wc.SetClipboardData(win32con.CF_UNICODETEXT, txt.encode()) wc.CloseClipboard() print('删除了'+str(n)+'个换行符\n') print(txt+'\n') stripClipboard()
保存并命名为“stripClipboard.py”。每当从论文里复制了文字后,只需运行
python stripClipboard.py接着再ctrl+v就能粘贴已去除所有换行符的文字内容。
例如,从论文中ctrl+v了如下文字:
In this paper, we propose a novel neural network model called RNN Encoder– Decoder that consists of two recurrent neural networks (RNN). One RNN encodes a sequence of symbols into a fixedlength vector representation, and the other decodes the representation into another sequence of symbols. The encoder and decoder of the proposed model are jointly trained to maximize the conditional probability of a target sequence given a source sequence. The performance of a statistical machine translation system is empirically found to improve by using the conditional probabilities of phrase pairs computed by the RNN Encoder–Decoder as an additional feature in the existing log-linear model. Qualitatively, we show that the proposed model learns a semantically and syntactically meaningful representation of linguistic phrases.
运行
python stripClipboard.py,则剪切板的内容变为:
In this paper, we propose a novel neural network model called RNN Encoder– Decoder that consists of two recurrent neural networks (RNN). One RNN encodes a sequence of symbols into a fixedlength vector representation, and the other decodes the representation into another sequence of symbols. The encoder and decoder of the proposed model are jointly trained to maximize the conditional probability of a target sequence given a source sequence. The performance of a statistical machine translation system is empirically found to improve by using the conditional probabilities of phrase pairs computed by the RNN Encoder–Decoder as an additional feature in the existing log-linear model. Qualitatively, we show that the proposed model learns a semantically and syntactically meaningful representation of linguistic phrases.
注1: 要使用win32clipboard需安装pypiwin32,可用
pip install pypiwin32来进行安装
注2: Mac下Python的剪切板操作将在另一篇文章里介绍
注3(已解决):处理中文字符时会乱码
相关文章推荐
- javascript利用控件对windows的操作实现原理与应用
- python 利用win32com操作excel
- window.clipboardData实现剪切板操作总结
- 如何利用Python和win32编程避免重复性体力劳动(三)——文本框操作:WM_GETTEXT 和WM_SETTEXT
- windows环境,用python实现SSH操作
- python之win32下,枚举进程,线程和线程对应的窗口的利用ctypes实现
- Python利用win32com操作Excel .
- java利用Jsch实现在windows平台远程操作linux服务器
- 利用Python实现Windows下的鼠标键盘模拟的实例代码
- python在windows下实现ping操作并接收返回信息的方法
- python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过autopy实现右键菜单和另存为操作
- EXTJS学习系列提高篇:第十二篇(转载)作者殷良胜,利用Ext实现类似Windows的操作
- Python利用splinter实现浏览器自动化操作
- win32下利用python操作printer
- 如何利用Python和win32编程避免重复性体力劳动(二)——菜单操作:GetMenu,GetSubMenu,GetMenuItemID以及wParam的HIWORD&LOWORD
- Python 3 利用 subprocess 实现管道( pipe )交互操作读/写通信
- 利用IContextMenu接口实现Windows外壳的上下文菜单操作
- VC 操作word部分代码(利用剪切板取得Word中的图片,ClipBoard, Addpicture)
- javascript利用控件对windows的操作实现原理与应用
- 如何利用Python和win32编程避免重复性体力劳动(四)——下拉列表操作:CB_SETCURSEL、CBN_SELENDOK和CBN_SELCHANGE