# 定义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统计一个文本中重复行数的方法
python统计一个文本中重复行数的方法 这篇文章主要介绍了python统计一个文本中重复行数的方法,涉及针对Python中dict对象的使用及相关本文的操作,具有一定的借鉴价值,需要的朋友可以参考下 ...
- 再用python写一个文本处理的东东
朋友遇到一点麻烦,我自告奋勇帮忙.事情是这样的: - 他们的业务系统中,数据来自一个邮箱: - 每一个邮件包含一条记录: - 这些记录是纯文本的,字段之间由一些特殊字符分隔: - 他们需要从邮箱中批量 ...
- ZeroMQ接口函数之 :zmq_z85_decode – 从一个用Z85算法生成的文本中解析出二进制密码
ZeroMQ 官方地址 :http://api.zeromq.org/4-0:zmq_z85_decode zmq_z85_decode(3) ØMQ Manual - ØMQ/4.1 ...
- Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组
Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组 import time dt=time.strptime('2019-08-08 11:32:23', ...
- 用python做一个搜索引擎(Pylucene)
什么是搜索引擎? 搜索引擎是“对网络信息资源进行搜集整理并提供信息查询服务的系统,包括信息搜集.信息整理和用户查询三部分”.如图1是搜索引擎的一般结构,信息搜集模块从网络采集信息到网络信息库之中(一般 ...
- python练习一—文本转化渲染为html
想学习python已经很久了,以前使用ArcGIS的时候学习过一些简单的python语法,用来进行一些简单的GIS数据处理,但是后来并没有用到工作中也就荒废了,后来断断续续看过一些,最近想学习一门新的 ...
- python爬虫的页面数据解析和提取/xpath/bs4/jsonpath/正则(1)
一.数据类型及解析方式 一般来讲对我们而言,需要抓取的是某个网站或者某个应用的内容,提取有用的价值.内容一般分为两部分,非结构化的数据 和 结构化的数据. 非结构化数据:先有数据,再有结构, 结构化数 ...
- python爬虫---爬虫的数据解析的流程和解析数据的几种方式
python爬虫---爬虫的数据解析的流程和解析数据的几种方式 一丶爬虫数据解析 概念:将一整张页面中的局部数据进行提取/解析 作用:用来实现聚焦爬虫的吧 实现方式: 正则 (针对字符串) bs4 x ...
- Python爬虫beautifulsoup4常用的解析方法总结(新手必看)
今天小编就为大家分享一篇关于Python爬虫beautifulsoup4常用的解析方法总结,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧摘要 如何用beau ...
随机推荐
- HDU 6623 Minimal Power of Prime(思维)题解
题意: 已知任意大于\(1\)的整数\(a = p_1^{q_1}p_2^{q_2} \cdots p_k^{q_k}\),现给出\(a \in [2,1e18]\),求\(min\{q_i\},q ...
- macOS & pbcopy
macOS & pbcopy copy from command line pbcopy $ whoami | pbcopy # xgqfrms-mbp $ echo "hello, ...
- CSS multi colors circle
CSS multi colors circle <!DOCTYPE html> <html lang="zh-Hans"> <head> < ...
- ES2021 & Pipeline operator (|>) / 管道运算符 |>
ES2021 & Pipeline operator (|>) / 管道运算符 |> demo "use strict"; /** * * @author xg ...
- Android Studio 4.x
Android Studio 4.x https://developer.android.com/studio https://d.android.com/r/studio-ui/whats-new- ...
- onsen & UI & vue & mobile UI
onsen & UI vue & mobile UI $ npm i onsenui vue-onsenui # OR $ npm i -S onsenui vue-onsenui h ...
- js & sort array object
js & sort array object sort array object in js https://flaviocopes.com/how-to-sort-array-of-obje ...
- vue watch & arrow function bug
vue watch & arrow function bug watch: { GeoJSON: function(newValue, oldValue) { log(`\n\n\nGeoJS ...
- MongoDB的下载、安装与部署
1.什么是MongoDB? 它是介于关系型数据库和非关系型数据库之间的一种NoSQL数据库,用C++编写,是一款集敏捷性.可伸缩性.扩展性于一身的高性能的面向文档的通用数据库. 2.为什么要用Mong ...
- 10000星光值兑换一个的VAST将如何搅动NGK算力市场?
加密数字货币是私人而非政府所发行的数字资产,具有自己的"货币"账户单位,在可以预见的未来三年之内,加密数字货币将覆盖至少全世界五分之一的人口.为此,NGK方面也做出了自己的努力,在 ...