我一直在嘗試編寫一個 Python 腳本來完成 20 種思科配置。到目前為止,我得到了一個腳本來處理一個配置,它解析出沒有802.1x authentication*接口命令的接口。我無法從列表中刪除interface Tengig和interface vlan*。最好的方法是什么?我嘗試了以下方法但沒有成功。也許我只是用錯了它們?list.remove(Interface Vlan*) for item in list(NoDot1x): somelist.remove("Interface Vlan*")代碼: #Int Modules from ciscoconfparse import CiscoConfParse #Define what to Parse parse = CiscoConfParse("/home/jbowers/Configs/SwithConfig") #Define all Interfaces without Authentication * commands all_intfs = parse.find_objects(r"^interf") NoDot1x = list() NoDot1x = parse.find_objects_wo_child(r'^interface', r'authentication') #Display Results for obj in NoDot1x: print obj.text #Remove Uplinks for item in list(NoDot1x): somelist.remove("Interface Vlan*")這里是#Display Results 的輸出。interface Port-channel1interface FastEthernet1interface GigabitEthernet1/1interface TenGigabitEthernet5/1interface TenGigabitEthernet5/2interface TenGigabitEthernet5/3interface TenGigabitEthernet5/4interface TenGigabitEthernet5/5interface TenGigabitEthernet5/6interface TenGigabitEthernet5/7interface TenGigabitEthernet5/8interface TenGigabitEthernet6/1interface TenGigabitEthernet6/2interface TenGigabitEthernet6/3interface TenGigabitEthernet6/4interface TenGigabitEthernet6/5interface TenGigabitEthernet6/6interface TenGigabitEthernet6/7interface TenGigabitEthernet6/8interface GigabitEthernet7/23interface GigabitEthernet8/17interface GigabitEthernet9/2interface Vlan1
1 回答

白衣染霜花
TA貢獻1796條經驗 獲得超10個贊
Python 中 list 對象提供的 remove 函數將嘗試找到與輸入的字符串完全匹配的內容,如果找到則刪除,否則會出錯。
#Remove Uplinks
for item in list(NoDot1x):
somelist.remove("Interface Vlan*")
以上不會使用通配符“*”。我想你想要更像的東西:
for item in list(NoDot1x):
if "Interface Vlan" in item:
somelist.remove(item)
如果您需要更多復雜性,請查看重新導入。
添加回答
舉報
0/150
提交
取消