Windows下利用win32clipboard实现Python的剪切板(Clip - 在线留言 - 长春市隆兴伟业物流有限公司
现在的位置: 主页 > 在线留言 > 文章正文
Windows下利用win32clipboard实现Python的剪切板(Clip
作者:长春市隆兴伟业物流有限公司 来源:www.lxwywl.com 发布时间:2018-01-07 23:40:42
Windows下利用win32clipboard实现Python的剪切板(Clipboard)操作

最近翻译论文的时候发现复制过来的文字经常带有很多的换行符,为了方便的去除这些换行符,写了一个python小方法。
代码如下:

import win32clipboard as wc import win32con def stripClipboard(): wc.OpenClipboard() txt = wc.GetClipboardData(win32con.CF_TEXT) txt=txt.strip().replace("\r\n"," ").replace("\n"," ").replace("\r"," ") wc.EmptyClipboard() wc.SetClipboardData(win32con.CF_TEXT, txt) wc.CloseClipboard() print(txt) 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的剪切板操作将在另一篇文章里介绍

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:仙桃网站制作 http://xiantao.666rj.com


  • 上一篇:PHP解析URL并得到URL中的参数
  • 下一篇:最后一页
  • 
    COPYRIGHT © 2015 长春市隆兴伟业物流有限公司 ALL RIGHTS RESERVED.
    本站所有原创信息,未经许可请勿任意转载或复制使用 网站地图 技术支持:肥猫科技
    精彩专题:网站建设
    购买本站友情链接、项目合作请联系客服QQ:2500-38-100