b4和tncl_extract_UNCL_new
# -*- coding:utf-8 -*-
import re '''
适应新版本 注意:
1)17A文件改完后缀后,需要转为UTF-8无BOM格式,才能正确处理。
2)fr = open(filename,encoding='utf-8') ''' year='17A'#用户自定义
ss='./data/'#根目录
filename = ss+'UNCL%s.txt'%year#输入文件名 def tncl_note(): p4= r"^(?:\s{5}|X\s{4}|\W\s{4})(\w+)\s+\w.+\n"
p1 = r"^(?:\s{5}|X\s{4}|\W\s{4})(\d\d\d\d)\s\s[A-Z].+\]$"#匹配tncl_id
p2 = r"^(?:\s{5}|X\s{4}|\W\s{4})(\w+)\s+\w.+\n"#匹配tncl_tag
p3 = r"^(?:\s{5}|X\s{4}|\W\s{4})\w+\s+(\w.+)\n"#匹配tncl_name
p4 = r"^\s{14}([^ ].+)\n"#匹配tncl_desc和#Note内容 p5 = r"^\s{11}Note:\s\n"#Note pattern1 = re.compile(p1)
pattern2 = re.compile(p2)
pattern3 = re.compile(p3)
pattern4 = re.compile(p4) pattern5 = re.compile(p5) fr = open(filename,encoding='utf-8')
temp = str();
flag = 0
w2 = open(ss+'tncl_ori%s.txt'%year,'a')#a代表追加 w代表重写
flag1=0
for line in fr.readlines():
matcher1 = re.findall(pattern1,line)
matcher2 = re.findall(pattern2,line)
matcher3 = re.findall(pattern3,line)
matcher4 = re.findall(pattern4,line)
matcher5 = re.findall(pattern5,line) #print matcher if matcher1:
for g in matcher1:
flag = 1
temp = g continue;
if matcher2 and(flag==1 or 4)and(temp!=''): flag = 2
w2.write("\"\n"+temp+",")
for j in matcher2:
for k in j:
w2.write(k) if matcher3 and flag==2:
flag = 3
w2.write(",")
for j in matcher3:
for k in j:
w2.write(k)
w2.write(",\"")
if matcher4 and (flag==3 or flag==4):
flag=4
for j in matcher4:
for k in j:
w2.write(k) if ((matcher5!=[])and(flag == 4)):
# flag = 5
w2.write("\",\"")
# flag1=1 w2.write("\"")
w2.close( )
def join(): f1= open(ss+'tncl_ori%s.txt'%year) list_note=[]
for line1 in f1:
# print(line1) list_note.append(line1) f1.close()
# print(list_note[1].split(','))
# print("%s_%s,%s\n"%(list_note[1].split(',')[0],list_note[1].split(',')[1],list_note[1].strip('\n')))
# list_note[i].strip('\n')
# print(list_note)
f2_w1= open(ss+'tred%s.csv'%year,'a')
f2_w2= open(ss+'b4_%s.csv'%year,'a')
# for i in range(len(list_note)):
# i=0 for i in range(1,len(list_note)): str11="%s_%s,%s\n"%(list_note[i].split(',')[0],list_note[i].split(',')[1],list_note[i].strip('\n')) str12="%s_%s,%s,%s\n"%(list_note[i].split(',')[0],list_note[i].split(',')[1],list_note[i].split(',')[1],year)
f2_w1.write(str11)
f2_w2.write(str12) f2_w1.close()
f2_w2.close()
# f2.close() if __name__ == '__main__': tncl_note()
join()
b4和tncl_extract_UNCL_new的更多相关文章
- Google数据中心B4网络具体实现
① 背景介绍 Google的网络有两种,一种是数据中心内部网络,另外一种是WAN网,其中WAN网又分为两种:一是数据中心之间的互联网络,属于内部网络(G-Scale Network),另外一种是面向I ...
- B4 and After: Managing Hierarchy, Partitioning, and Asymmetry for Availability and Scale in Google’s Sofware-Defined WAN
B4及之后:为谷歌软件定义WAN的可用性和扩展管理层次化.划分和不对称 本文为SIGCOMM 2018会议论文,由谷歌提供. 笔者翻译了该论文.由于时间仓促,且笔者英文能力有限,错误之处在所难免:欢迎 ...
- Google B4网络阅读记录(翻译)
3.设计 这一章我们描述软件定义广域网架构的细节. 3.1.概述 我们的软件定义网络从逻辑上可以看做三层,如图所示, B4服务于多个广域网节点,每个节点都有很多服务器集群.在每个B4节点内,交换机硬件 ...
- [转帖]B4. Concurrent JVM 锁机制(synchronized)
B4. Concurrent JVM 锁机制(synchronized) https://www.cnblogs.com/zlxyt/p/11050346.html 挺好的 感觉这个文章写的 不过想要 ...
- Python小白的数学建模课-B4. 新冠疫情 SIR模型
Python小白的数学建模课-B4. 新冠疫情 SIR模型 传染病的数学模型是数学建模中的典型问题,常见的传染病模型有 SI.SIR.SIRS.SEIR 模型. SIR 模型将人群分为易感者(S类). ...
- 【MYSQL】MYSQL报错解决方法: Warning: (3719, "'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8M B4 in a future release."
用python3.6.5创建mysql库时出现如下报错,虽然报错,但是数据库可以插入成功. D:\python3\lib\site-packages\pymysql\cursors.py:170: W ...
- 第十章 优先级队列 (b4)完全二叉堆:批量建堆
- 第八章 高级搜索树 (b4)B-树: 插入
- b4
吴晓晖(组长) 过去两天完成了哪些任务 昨天FloatingActionButton和权限获取调整 今天复习,没写东西,晚点有空了写 展示GitHub当日代码/文档签入记录 接下来的计划 推荐算法 还 ...
随机推荐
- Spring MVC国际化
本文基于Spring MVC 注解-让Spring跑起来.本文提到的国际化是Spring实现国际化的方案之一. (1) 在applicationContext.xml中添加以下配置信息: <!- ...
- NodeJS框架express的路径映射(路由)功能及控制
我 们知道Express是一个基于NodeJS的非常优秀的服务端开发框架,本篇CSSer将提供express框架的route和route control章节,route实现了客户端请求的URL的路径映 ...
- linux一些基本常识(四)
tail -f时时监控 一开启内存最小位u原则,尽量优化代码 grep -v "" /etc/passwd 这样行不行 怎么清除last nice调整进程运行级别 pkill是匹配 ...
- Java HashMap,LinkedHashMap,TreeMap
Java为数据结构中的映射定义了一个接口java.util.Map;它有四个实现类,分别是HashMap Hashtable LinkedHashMap 和TreeMapMap主要用于存储健值对,根据 ...
- 2014年可用的TRACKER服务器大全
udp://tracker.openbittorrent.com:80/announceudp://tracker.publicbt.com:80/announcehttp://pubt.net:27 ...
- 在MyEclipse Tomcat可以运行但是在Tomcat 6.x上却不可以运行
- Plants vs. Zombies(二分好题+思维)
Plants vs. Zombies http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5819 BaoBao and DreamG ...
- mongo通信协议
先是一个包头: struct MsgHeader { int32 messageLength; // total message size, including this int32 requestI ...
- SyntaxError: Non-ASCII character '\xe5' in file D:/pcode/xx.py on line 21, but no encoding declared
from selenium import webdriver from datetime import * import time starttime = datetime.now() print ( ...
- 对于Android开发,啥是高级工程师?
最近一直在思考自己的技术方向.新的技术永远都是层出不穷,kotlin,flutter,小程序,轻应用等等,但是作为一个老鸟,新的东西,永远都是学不完的,想在新的技术上迭代学习出一个新高度,而增加自己的 ...