- 论坛徽章:
- 0
|
回复 1# 1747768292 - # encoding: utf-8
- data = """ <Analog NoInSource="224" maxValue="300.0000" minValue="0.0000" name="RBC-VIA接口柜1电压" show_name="RBC-VIA接口柜1电压" thresholdDown="176.0000" thresholdUpper="253.0000" unit="V"/>
- <Analog NoInSource="225" maxValue="20.0000" minValue="0.0000" name="RBC-VIA接口柜1电流" show_name="RBC-VIA接口柜1电流" thresholdDown="0.0000" thresholdUpper="10.0000" unit="A"/>
- <Analog NoInSource="226" maxValue="300.0000" minValue="0.0000" name="RBC-VIA接口柜2电压" show_name="RBC-VIA接口柜2电压" thresholdDown="176.0000" thresholdUpper="253.0000" unit="V"/>
- <Analog NoInSource="227" maxValue="20.0000" minValue="0.0000" name="RBC-VIA接口柜2电流" show_name="RBC-VIA接口柜2电流" thresholdDown="0.0000" thresholdUpper="10.0000" unit="A"/>
- <Analog NoInSource="228" maxValue="300.0000" minValue="0.0000" name="RBC-临时限速1电压" show_name="RBC-临时限速1电压" thresholdDown="176.0000" thresholdUpper="253.0000" unit="V"/>
- <Analog NoInSource="229" maxValue="20.0000" minValue="0.0000" name="RBC-临时限速1电流" show_name="RBC-临时限速1电流" thresholdDown="0.0000" thresholdUpper="10.0000" unit="A"/>
- <Analog NoInSource="230" maxValue="300.0000" minValue="0.0000" name="RBC-临时限速2电压" show_name="RBC-临时限速2电压" thresholdDown="176.0000" thresholdUpper="253.0000" unit="V"/>
- <Analog NoInSource="231" maxValue="20.0000" minValue="0.0000" name="RBC-临时限速2电流" show_name="RBC-临时限速2电流" thresholdDown="0.0000" thresholdUpper="10.0000" unit="A"/>
- <Analog NoInSource="232" maxValue="300.0000" minValue="0.0000" name="RBC-临时限速3电压" show_name="RBC-临时限速3电压" thresholdDown="176.0000" thresholdUpper="253.0000" unit="V"/>
- <Analog NoInSource="233" maxValue="20.0000" minValue="0.0000" name="RBC-临时限速3电流" show_name="RBC-临时限速3电流" thresholdDown="0.0000" thresholdUpper="10.0000" unit="A"/>"""
- import re
- line = re.compile("<Analog (.*)/>")
- kv = re.compile('(\w+)="(\S+)"')
- for l in line.findall(data):
- this = {}
- for k,v in kv.findall(l):
- this[k] = v
- if this["unit"] == "V":
- output = [ "=".join([k,v]) for k,v in this.iteritems()]
- print ",".join(output)
复制代码- name=RBC-VIA接口柜1电压,thresholdUpper=253.0000,show_name=RBC-VIA接口柜1电压,maxValue=300.0000,minValue=0.0000,NoInSource=224,thresholdDown=176.0000,unit=V
- name=RBC-VIA接口柜2电压,thresholdUpper=253.0000,show_name=RBC-VIA接口柜2电压,maxValue=300.0000,minValue=0.0000,NoInSource=226,thresholdDown=176.0000,unit=V
- name=RBC-临时限速1电压,thresholdUpper=253.0000,show_name=RBC-临时限速1电压,maxValue=300.0000,minValue=0.0000,NoInSource=228,thresholdDown=176.0000,unit=V
- name=RBC-临时限速2电压,thresholdUpper=253.0000,show_name=RBC-临时限速2电压,maxValue=300.0000,minValue=0.0000,NoInSource=230,thresholdDown=176.0000,unit=V
- name=RBC-临时限速3电压,thresholdUpper=253.0000,show_name=RBC-临时限速3电压,maxValue=300.0000,minValue=0.0000,NoInSource=232,thresholdDown=176.0000,unit=V
复制代码 |
|