Windows下利用win32clipboard实现Python的剪切板(Clipboard)操作
来源:互联网 发布:linux epoll wait 编辑:程序博客网 时间:2024/06/06 00:08
最近翻译论文的时候发现复制过来的文字经常带有很多的换行符,为了方便的去除这些换行符,写了一个python小方法。
代码如下(适用于Python3):
import win32clipboard as wcimport win32condef 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 neuralnetwork model called RNN Encoder–Decoder that consists of two recurrentneural networks (RNN). One RNN encodesa sequence of symbols into a fixedlengthvector representation, and the otherdecodes the representation into another sequenceof symbols. The encoder and decoderof the proposed model are jointlytrained to maximize the conditional probabilityof a target sequence given a sourcesequence. The performance of a statisticalmachine translation system is empiricallyfound to improve by using the conditionalprobabilities of phrase pairs computedby the RNN Encoder–Decoder as anadditional feature in the existing log-linearmodel. Qualitatively, we show that theproposed model learns a semantically andsyntactically meaningful representation oflinguistic 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(已解决):处理中文字符时会乱码
阅读全文
0 0
- Windows下利用win32clipboard实现Python的剪切板(Clipboard)操作
- SAP对ClipBoard(剪切板)的操作
- SAP对ClipBoard(剪切板)的操作
- Windows下python获取剪切板的内容
- SWT 的拖放操作,DragSource 和 DropTarget 与剪切板(Clipboard)
- summernote的兼容ie的剪切板实现-clipboard
- Clipboard 剪切板的应用&&Action
- VC 操作word部分代码(利用剪切板取得Word中的图片,ClipBoard, Addpicture)
- MFC之剪切板(Clipboard)操作
- 剪切板clipboard
- Mac下用python操作剪切板
- android中剪切板的应用(clipboard)
- WINDOWS中关于剪切板的编程操作
- Delphi的windows剪切板操作函数
- WINDOWS 剪切板操作
- Windows c++剪切板操作
- windows下的剪切板编程详解
- windows下的剪切板编程详解
- pktgen 运行时选项和命令
- Pktgen CLI样例程序
- pktgen CLI库指南
- Pktgen 运行脚本文件
- VirtualBox Linux Mount共享文件夹
- Windows下利用win32clipboard实现Python的剪切板(Clipboard)操作
- 方正转型的悲哀
- COGS血帆海盗
- ereg()无法正常使用
- COGS 426. 血帆海盗 最小割定理
- python多进程学习
- Ubuntu Maven 配置
- Mysql5.7.19 winx64安装过程遇到的问题及解决办法
- Android属性动画(Property Animation)