我從HP設備獲取信息並將其存儲在名爲data
的變量中。現在在Python中查找並只提取所需的信息
,我想從輸出,其中一個例子下面是Chassis:
和Serial Number:
僅提取的值(I通過鍵入命令show module
獲得它):
============================
coaza077-cor-01> show module
Status and Counters - Module Information
Chassis: 2900-24G J9049A Serial Number: SG748KI09F
Slot Module Description Serial Number
----- ---------------------------------------- --------------
coaza077-cor-01> exit
Do you want to log out [y/n]? y
=============================
下面的代碼是我的試圖做到這一點:
sList = os.linesep.join([s for s in data.splitlines() if s])
for i in range(0,len(sList)):
if (sList[i].lower()).find('Chassis') >= 0:
#DEVICE PROCESSOR
device_processor= _parse.getdata(sList[i].lower(), 'Chassis:', ' ')
if debugging == "_HP2900" or debugging == "ALL": print "_HP2900.py", "Processor", device_processor
if (sList[i].lower()).find('Serial Number') >= 0:
print 'Serial Number'
#DEVICE SERIAL NUMBER
device_serial= (_parse.serial_number(sList[i].lower()[len('Serial Number'):])).upper()
if debugging == "_HP2900" or debugging == "ALL": print "_HP2900.py", "Serial", device_serial
..但我似乎無法得到只有我需要的兩個值。我對Python很陌生,不確定我是否正確地處理了這個問題。
我怎樣才能得到我需要的領域?
什麼是不工作?你有錯誤嗎?或者結果不是你所期望的? – Cristina