我是新手,需要pyparsing的帮助。需要将以下输出解析成字典对象。
MONLB01> sh lb vserver montest_4567_VS2
montest_4567_VS2 (167.22.55.130:4567) - TCP Type: ADDRESS
State: DOWN
Effective State: DOWN
Client Idle Timeout: 9000 sec
Down state flush: ENABLED
Configured Method: ROUNDROBIN
Mode: IP
Persistence: NONE
Connection Failover: DISABLED
1) montest_6248_S3 (177.24.41.3: 6248) - TCP State: DOWN Weight: 1
2) montest_6248_S4 (177.24.41.3: 6248) - TCP State: DOWN Weight: 1
Done
更新
from pyparsing import \
Literal, Word, ZeroOrMore, Group, Dict, Optional, \
printables, ParseException, restOfLine
import pprint
inibnf = None
def inifile_BNF():
<!!!!!Parsing Logic!!!Need Help here>
return inibnf
pp = pprint.PrettyPrinter(2)
def test( strng ):
print strng
try:
iniFile = file(strng)
iniData = "".join( iniFile.readlines() )
bnf = inifile_BNF()
tokens = bnf.parseString( iniData )
pp.pprint( tokens.asList() )
except ParseException, err:
print err.line
print " "*(err.column-1) + "^"
print err
iniFile.close()
ini = test("netscalerout.txt")
从上面的内容可以看出,我需要使用pyparsing库编写解析逻辑