# -*- coding:utf-8 -*-
import re year="17A"
ss='./data/'
filename = ss+'EDCD%s.txt'%year '''
适应新版本
''' p1 = r"^\s{4}(?:X|\W)\s{2}(C\d\d\d)\s.+\n"
p2 = r"^(\d\d\d)\s{4}\d{4}\s{2}.+[CM]\s+(?:.*\.\.\d+|.*)\n"#C n3
p3 = r"^\d\d\d\s{4}(\d{4})\s{2}.+[CM]\s+(?:.*\.\.\d+|.*)\n"
p4 = r"^\d\d\d\s{4}\d{4}\s{2}.+([CM])\s+(?:.*\.\.\d+|.*)\n"
p5 = r"^\d\d\d\s{4}\d{4}\s{2}.+[CM]\s+((?:.*\.\.\d+|.*))\n" p6 = r"^(\d\d\d)\s{4}\d{4}\s{2}.+[^\d]$\n"
p7 = r"^\d\d\d\s{4}(\d{4})\s{2}.+[^\d]$\n"
p8 = r"^\s{13}.+([CM])\s+(?:.*\.\.\d+|.*)\n"
p9 = r"^\s{13}.+[CM]\s+((?:.*\.\.\d+|.*))\n"
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)
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)
#print matcher
w2 = open(ss+'b3_%s.csv'%year,'a')#a代表追加 w代表重写
if matcher1:
flag = 1
for j in matcher1:
temp = j
if ((matcher2!=[])and(flag ==1 or 5 or 9)):
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) if ((matcher4!=[])and(flag ==3)):
flag = 4
w2.write(",")
for j in matcher4:
for k in j:
w2.write(k) if ((matcher5!=[])and(flag ==4)):
flag = 5
w2.write(",")
for j in matcher5:
for k in j:
w2.write(k) if ((matcher6!=[])and(flag ==1 or 5 or 9)):
flag = 6
w2.write("\n"+temp+",")
for j in matcher6:
for k in j:
w2.write(k)
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) if ((matcher9!=[])and(flag ==8)):
flag = 9
w2.write(",")
for j in matcher9:
for k in j:
w2.write(k)
w2.close( )

b3_trcd_EDCD_new的更多相关文章

随机推荐

  1. Redis基本操作-string

    Redis的5种数据结构:string.list.hash.set和zset; Redis 所有的数据结构都是以唯一的 key 字符串作为名称,然后通过这个唯一 key 值来获取相应的 value 数 ...

  2. ASP.NET MVC 项目文件夹结构

    首先,打开Visual Studio, 新建一个demo 项目的solution,选择 Blank Soution. 第二步,创建文件夹,按自己的需求创建.在这个Demo 中,我将创建4个文件夹. P ...

  3. JS中回调函数的使用

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. DNN例子

    [Tensorflow DNNClassifier ValueError]http://stackoverflow.com/questions/40264622/tensorflow-dnnclass ...

  5. 手动安装yii2.0-redis扩展

    1.点击下载:yii2.0-redis扩展 2.把下载的扩展文件放到vendor/yiisoft/下,命名为yii2-redis 3.修改vender/yiisoft/下的extensions.php ...

  6. 使用Font Awesome替换你的网站图标(icons 图标)

    http://www.thinkcmf.com/font/icons/ 第一次使用 Font Awesome 发现相当的爽呀!它的图标很全,能够帮你节约时间去找图片.下面就来一起学习吧: 1: 去官方 ...

  7. Drying

    Drying http://poj.org/problem?id=3104 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2 ...

  8. pyhon之函数参数

    #函数的参数分为形参和实参,其中形参就是形式参数,是在创建函数的时候定义,实参就是实际参数,是在调用的函数的时候创建,这个并不是重点,具体#的参数内部,我们可以把参数分为以下4种# 1.普通参数# 2 ...

  9. Spring框架的Bean管理的配置文件方式

    1. id属性和name属性的区别 * id -- Bean起个名字,在约束中采用ID的约束,唯一 * 取值要求:必须以字母开始,可以使用字母.数字.连字符.下划线.句话.冒号 id:不能出现特殊字符 ...

  10. Castle ActiveRecord学习(五)使用HQL语句查询

    来源:http://www.cnblogs.com/Terrylee/archive/2006/04/12/372823.html 一.HQL简单介绍HQL全名是Hibernate Query Lan ...