博客
关于我
文献复制去换行 python
阅读量:346 次
发布时间:2019-03-04

本文共 1547 字,大约阅读时间需要 5 分钟。

实现功能:复制中英文文献,去除复制时出现的多余的换行符

github地址:

import timeimport sysimport osimport resys.path.append(os.path.abspath("SO_site-packages"))import pyperclip  # 引入模块print("文献复制中英结合版")print("literaturecopy_both english and chinese")print("version 0.4")print("by TophTab")print("support me via Alipay QR code,even $1 is big support to author.")print("赞助请转账支付宝二维码,即使是一元也是对作者的支持")recent_value = ""tmp_value="" # 初始化(应该也可以没有这一行,感觉意义不大。但是对recent_value的初始化是必须的)# E_pun = u',.!?()<>"\''# C_pun = u',。!?()《》“‘'# table_CtoE= {ord(f):ord(t) for f,t in zip(C_pun,E_pun)}# table_EtoC= {ord(f):ord(t) for f,t in zip(E_pun,C_pun)}    def English(recent_value):    changed_1= re.sub(r"\s{2,}", " ", recent_value) 	#将文本的换行符去掉,变成一个空格    # changed_2=changed_1.translate(table_CtoE)    pyperclip.copy(changed_1)					     #将修改后的文本写入系统剪切板中    print("\n英文_值变为: %s" % str(changed_1))  	# 输出已经去除换行符的文本    time.sleep(0.1)def Chinese(recent_value):    changed_1= re.sub(r"\s", "", recent_value) 	#将文本的换行符去掉,变成一个空格    # changed_2=changed_1.translate(table_EtoC)    pyperclip.copy(changed_1)						     #将修改后的文本写入系统剪切板中    print("\n中文_值变为: %s" % str(changed_1))  	# 输出已经去除换行符的文本    time.sleep(0.1)while True:    tmp_value = pyperclip.paste() 			# 读取剪切板复制的内容    try:        if tmp_value != recent_value:		#如果检测到剪切板内容有改动,那么就进入文本的修改            recent_value = tmp_value            if re.search("[\u2E80-\u9FFF]+",tmp_value) is not None:                Chinese(recent_value)            else:                English(recent_value)    except KeyboardInterrupt:  # 如果有ctrl+c,那么就退出这个程序。        break

转载地址:http://ufrq.baihongyu.com/

你可能感兴趣的文章
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>