# -*- coding:utf-8 -*-
import re ss="./data/"
year = '17A'
filename = ss+'EDSD%s.txt'%year '''
适应新版本 ''' p1 = r"^\s{4}(?:X|\W)\s{2}([A-Z]{3})\s\s.+\n"#TC
p2 = r"(^\d{3})\s{4}C\d{3}.+[CM]\s+\d\n"#
p3 = r"^\d{3}\s{4}(C\d{3}).+[CM]\s+\d\n"#C552
p4 = r"^\d{3}\s{4}C\d{3}.+([CM])\s+\d\n"#M
p5 = r"^\d{3}\s{4}C\d{3}.+[CM]\s+(\d)\n"#
p6= r"(^\d{3})\s{4}\d{4}.+[CM]\s{4}\d\s.*\.\.\d+\n|(^\d{3})\s{4}\w\d{3}\s.+[^\d]$\n"#单独的030
p7 =r"^\d{3}\s{4}(\d{4}).+[CM]\s{4}\d\s.*\.\.\d+\n|^\d{3}\s{4}(\w\d{3})\s.+[^\d]$\n"#单独的3286
p8 =r"^\d{3}\s{4}\d{4}.+([CM])\s{4}\d\s.*\.\.\d+\n|^\s{12}[A-Z].+([CM])\s{4}\d\s.*\.\.\d+\n"#单独的M
p9 =r"^\d{3}\s{4}\d{4}.+[CM]\s{4}(\d)\s.*\.\.\d+\n|^\s{12}[A-Z].+[CM]\s{4}(\d)\s.*\.\.\d+\n"#单独的1
p10 =r"^\d{3}\s{4}\d{4}.+[CM]\s{4}\d\s(.*\.\.\d+)\n|^\s{12}[A-Z].+[CM]\s{4}\d\s(.*\.\.\d+)\n"#单独的an..35 pattern1 = re.compile(p1)
pattern2 = re.compile(p2)
pattern3 = re.compile(p3)
pattern4 = re.compile(p4)
pattern5 = re.compile(p5)
pattern6 = re.compile(p6)
pattern7 = re.compile(p7)
pattern8 = re.compile(p8)
pattern9 = re.compile(p9)
pattern10 = re.compile(p10) fr = open(filename)
temp = ();
flag = 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)
matcher6 = re.findall(pattern6,line)
matcher7 = re.findall(pattern7,line)
matcher8 = re.findall(pattern8,line)
matcher9 = re.findall(pattern9,line)
matcher10 = re.findall(pattern10,line)
#print matcher
w2 = open(ss+'b2_%s.csv'%year,'a')#a代表追加 w代表重写
if (matcher1!=[]):
for g in matcher1:
flag = 1
temp = g
if ((matcher2!=[])and(flag ==1 or 2)):
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)
#复合的缺省为0000
w2.write(",0000")
if ((matcher4!=[])and(flag ==3)):
flag = 4
w2.write(",")
for j in matcher4:
for k in j:
w2.write(k)
#增加固定列year
w2.write(","+year)
if ((matcher5!=[])and(flag ==4)):
flag = 5
w2.write(",")
for j in matcher5:
for k in j:
w2.write(k)
w2.write(", ")
# print len(matcher6)
if(len(matcher6)==1 and matcher6!=[''] ): flag = 6
w2.write("\n"+temp+",")
for j in matcher6:
for k in j:
w2.write(k)
#单独的缺省为C000
w2.write(",C000")
if ((matcher7!=[])and(flag ==6)):
flag = 7
w2.write(",")
for j in matcher7:
for k in j:
w2.write(k)
if ((matcher8!=[])and(flag ==7)):
flag = 8
w2.write(",")
for j in matcher8:
for k in j:
w2.write(k)
#增加固定列year
w2.write(","+year)
if ((matcher9!=[])and(flag ==8)):
flag = 9
w2.write(",")
for j in matcher9:
for k in j:
w2.write(k)
if ((matcher10!=[])and(flag ==9)):
flag = 10
w2.write(",")
for j in matcher10:
for k in j:
w2.write(k)
w2.close( ) """
特殊情况 """

b2_trsd_EDSD_new的更多相关文章

随机推荐

  1. SpringBoot 常用注解(持续更新)

    SpringBoot 常用注解 @SpringBootApplication @Bean @ComponentScan @ControllerAdvice @ExceptionHandler @Res ...

  2. UI5-文档-导航栏

    UI5-文档-1-前言 UI5-文档-2-开发环境 UI5-文档-2.1-使用OpenUI5开发应用 UI5-文档-2.2-使用SAP Web IDE开发应用程序 UI5-文档-2.3-使用SAPUI ...

  3. .Net 常用开发工具

    ,net常用开发工具 LinqPad使用 LinqPad连接Oracle 使用 LINQPad 将linq转换为 lambda表达式 或者 SQL语句 LINQPad 4 初次使用心得 一.双击 二. ...

  4. 根据class操作div显示与隐藏

    <div class="otherComment" > <!-- style="display:none" --> 测试 </di ...

  5. 四大域对象,和jsp的九大隐式对象,已经el表达式的11个隐式对象

    四大域对象 1.PageContext :页面范围的数据 2.ServletRequest:请求范围的数据 3.HttpSession:回话范围的数据 4.ServletContext:应用范围的数据 ...

  6. 关于Integer的比较,今天又犯了一个低级错误,记录下

    今天查看以前所写的代码,看到有一部分被人改了,代码如下: if (orgId != organizationUpdateReq.getOrgId()) { //orgId的类型为Integer,org ...

  7. conflicting types for ‘方法名’ 的错误

    将main()的实现写在drawShapes(),drawCircle(),drawRectangle()...之前. 结果编译的时候出现了  conflicting types for " ...

  8. python判断unicode是否是汉字,数字,英文,或者其他字符

    下面这个小工具包含了 判断unicode是否是汉字,数字,英文,或者其他字符. 全角符号转半角符号. unicode字符串归一化等工作. 还有一个能处理多音字的汉字转拼音的程序,还在整理中. #!/u ...

  9. Validate the date format

    Validate the date format function checkdate(input) { var validformat = /^\d{2}\/\d{2}\/\d{4}$/; //Ba ...

  10. Containerpilot 配置文件模板

    { "consul": "{{ .CONSUL }}:8500", "logging": { "level": &quo ...