# 定义Tag的签注
controlAreaStart ="<ControlArea::黄冈>"
controlAreaEnd = "</ControlArea::黄冈>"
entity = "<!Entity=黄冈"
controlAreaStart ="<ControlArea::黄冈>"
controlAreaEnd = "</ControlArea::黄冈>"
baseVoltageStart ="<BaseVoltage::黄冈>"
baseVoltageEnd = "</BaseVoltage::黄冈>"
SubstationStart ="<Substation::黄冈>"
SubstationEnd = "</Substation::黄冈>"
voltageLevelStart ="<VoltageLevel::黄冈>"
voltageLevelEnd = "</VoltageLevel::黄冈>"
bayStart="<Bay::黄冈>"
bayEnd = "</Bay::黄冈>"
breakerStart ="<Breaker::黄冈>"
breakerEnd = "</Breaker::黄冈>"
disconnectorStart ="<Disconnector::黄冈>"
disconnectorEnd = "</Disconnector::黄冈>"
groundDisconnectorStart ="<GroundDisconnector::黄冈>"
groundDisconnectorEnd = "</GroundDisconnector::黄冈>"
busbarSectionStart ="<BusbarSection::黄冈>"
busbarSectionEnd = "</BusbarSection::黄冈>"
aclineStart = "<ACLine::黄冈>"
aclineEnd = "</ACLine::黄冈>"
aCLineSegmentStart ="<ACLineSegment::黄冈>"
aCLineSegmentEnd = "</ACLineSegment::黄冈>"
aCLineDotStart = "<ACLineDot::黄冈>"
aCLineDotEnd = "</ACLineDot::黄冈>"
dCLineSegmentStart = "<DCLineSegment::黄冈>"
dCLineSegmentEnd = "</DCLineSegment::黄冈>"
dCLineDotStart = "<DCLineDot::黄冈>"
dCLineDotEnd = "</DCLineDot::黄冈>"
rectifierInverterStart = "<RectifierInverter::黄冈>"
rectifierInverterEnd = "</RectifierInverter::黄冈>"
#还有一些没有定义
#获取标签在文件中的起始和结束行数
'''
参数 
filePath文件路径
tagStart:标签起始值 
tagEnd标签结束值 
返回值
lineStart:起始行
lineEnd:结束行
'''
def getTagStartEndLineNum(filePath, tagStart, tagEnd):
    if((filePath is not None) and (tagStart is not None) and (tagEnd is not None)):
        f = open(filePath, "r+", encoding='GBK')
        for num, value in enumerate(f, 1):
            if (value.startswith(tagStart)):
                lineStart = num
            if (value.startswith(tagEnd)):
                lineEnd = num
        f.close()
        return lineStart, lineEnd
    else:
        return
#从起始行到结束行的内容
'''
参数 
filePath文件路径
lineStart:起始行
lineEnd:结束行
返回值
fileComm:返回的内容
'''
def lineCent(filePath,lineStart, lineEnd):
    if((filePath is not None) and (lineStart is not None) and (lineEnd is not None)):
        f = open(filePath, "r+", encoding='GBK')
        fileComm = []
        for line in f.readlines()[lineStart+2:lineEnd-1]:
            print(line)
            fileComm.append(line)
        f.close()
        return fileComm
    else:
        return
'''
下面以测试以aclineStart aclineEnd 的标签为例
分为三步进行操作
具体操作如下
'''
#1  获取acline在本文件里面的lineStart:起始行 lineEnd:结束行
fliePath="黄冈_20191126_235500.CIME"
lineStart, lineEnd = getTagStartEndLineNum(fliePath, aclineStart, aclineEnd)#aclineStart aclineEnd 的标签为例
print(lineStart)
print(lineEnd)
#2 获取acline在本文件里面的lineStart:起始行 lineEnd:结束行 返回的结果
flieList = lineCent(fliePath,lineStart, lineEnd)
print(flieList)
import sqlite3
conn = sqlite3.connect('test.db')
cursor = conn.cursor()
cursor.execute('''create table ACLine(Num varchar(20),mRID varchar(20),name varchar(20),pathName varchar(20),aclnNum integer)''')
#3 返回的结果进行入库操作
for line in flieList:
    AA,A, B, C, D,E = line.split(" ")
    print(AA)
    print(A)
    print(B)
    print(C)
    print(D)
    print(E)
    sql = "insert into ACLine(Num,mRID,name,pathName,aclnNum) values(" + A + "," + B + ",'" + C + "','" + D + "'," + E + ')'
    print(sql)
    cursor.execute(sql)
conn.commit()
conn.close()

python对一个文本的解析的更多相关文章

  1. python统计一个文本中重复行数的方法

    python统计一个文本中重复行数的方法 这篇文章主要介绍了python统计一个文本中重复行数的方法,涉及针对Python中dict对象的使用及相关本文的操作,具有一定的借鉴价值,需要的朋友可以参考下 ...

  2. 再用python写一个文本处理的东东

    朋友遇到一点麻烦,我自告奋勇帮忙.事情是这样的: - 他们的业务系统中,数据来自一个邮箱: - 每一个邮件包含一条记录: - 这些记录是纯文本的,字段之间由一些特殊字符分隔: - 他们需要从邮箱中批量 ...

  3. ZeroMQ接口函数之 :zmq_z85_decode – 从一个用Z85算法生成的文本中解析出二进制密码

    ZeroMQ 官方地址 :http://api.zeromq.org/4-0:zmq_z85_decode zmq_z85_decode(3)         ØMQ Manual - ØMQ/4.1 ...

  4. Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组

    Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组 import time dt=time.strptime('2019-08-08 11:32:23', ...

  5. 用python做一个搜索引擎(Pylucene)

    什么是搜索引擎? 搜索引擎是“对网络信息资源进行搜集整理并提供信息查询服务的系统,包括信息搜集.信息整理和用户查询三部分”.如图1是搜索引擎的一般结构,信息搜集模块从网络采集信息到网络信息库之中(一般 ...

  6. python练习一—文本转化渲染为html

    想学习python已经很久了,以前使用ArcGIS的时候学习过一些简单的python语法,用来进行一些简单的GIS数据处理,但是后来并没有用到工作中也就荒废了,后来断断续续看过一些,最近想学习一门新的 ...

  7. python爬虫的页面数据解析和提取/xpath/bs4/jsonpath/正则(1)

    一.数据类型及解析方式 一般来讲对我们而言,需要抓取的是某个网站或者某个应用的内容,提取有用的价值.内容一般分为两部分,非结构化的数据 和 结构化的数据. 非结构化数据:先有数据,再有结构, 结构化数 ...

  8. python爬虫---爬虫的数据解析的流程和解析数据的几种方式

    python爬虫---爬虫的数据解析的流程和解析数据的几种方式 一丶爬虫数据解析 概念:将一整张页面中的局部数据进行提取/解析 作用:用来实现聚焦爬虫的吧 实现方式: 正则 (针对字符串) bs4 x ...

  9. Python爬虫beautifulsoup4常用的解析方法总结(新手必看)

    今天小编就为大家分享一篇关于Python爬虫beautifulsoup4常用的解析方法总结,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧摘要 如何用beau ...

随机推荐

  1. Java中的变量之成员变量、本地变量与类变量

    Java中的变量: 1.成员变量(实例变量,属性) 2.本地变量(局部变量) 3.类变量(静态属性) 一.成员变量(实例变量,属性) 1.1-成员变量:(在类中定义,    访问修饰符   修饰符   ...

  2. redis键过期时间

    redis服务器中每个数据库都是一个redisDb,而redisDb实质上是一个字典的模型,数据库的每一个键都是一个字典的键值,对数据库的增删改查也就是对字典对象的增删改查. redis在维护带有过期 ...

  3. UA 广告 All In One

    UA 广告 All In One UA 广告是什么 广告投放 / 市场营销 互联网营销和分析专用名词速览 http://www.chinawebanalytics.cn/digital-marketi ...

  4. Github OAuth All In One

    Github OAuth All In One new https://docs.github.com/en/free-pro-team@latest/developers/apps/authoriz ...

  5. js double 精度损失 bugs

    js double 精度损失 bugs const arr = [ 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 ]; // [ ...

  6. auto embedded component in an online code editor

    auto embedded component in an online code editor how to auto open a component in the third parts onl ...

  7. Taro Next

    Taro Next Taro 2.0 https://aotu.io/notes/2020/02/03/taro-next-alpha/index.html Taro Next 的迁移指南 https ...

  8. image to cur (cursor icons)

    image to cur (cursor icons) mouse-cursor-pointer https://onlineconvertfree.com/convert-format/jpg-to ...

  9. Techme Inc热心公益事业 积极开展公益活动

    从2015年起,Techme inc(公司编号:20151524696)便通过优质的产品和服务,帮助顾客实现营养与健康的目标.与此同时,Techme inc(公司编号:20151524696)多年来始 ...

  10. NGK的去中心化自治实践,更人性化的DAO

    2020年,DeFi市场市场火爆的同时,引爆了流动性挖矿的市场.行业内对DAO的思考也在源源不断进行,特别项目治理通证发行之前,DAO的去中心化的治理理念,是区块链属性中的重要的一环,也已引发了不同项 ...