我一直在尝试编写一个 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
提交
取消