2016-11-04 53 views
0

我是一個沒有編程經驗的網絡工程師,最近在python中,但每天都做小改進。如果在一個字符串中搜索Python多個

我需要在IF語句一樣越來越多的比賽有所幫助:

if "access-class 30" in output and "exec-timeout 5 5" in output: 
    print ('###### ACL VTY OK!!! ######') 

是否可以檢查多個關鍵字在一個字符串? 感謝您的所有時間。

+1

的[檢查是否在另一個字符串中存在多個字符串]可能的複製(http://stackoverflow.com/questions/3389574/check-if-multiple-strings-exist-in-another-string) –

回答

1

使用all功能與發電機的表達:

data = ["access-class 30", "exec-timeout 5 5"] 
if all(s in output for s in data): 
    print('###### ACL VTY OK!!! ######') 
+0

TigerhawksT3 ,謝謝它工作得很好。 –

0

是的,它是可能的。

您可以使用正則表達式(正則表達式)。

import re 
li = [] # List of all the keywords 
for l in li 
    for m in re.finditer(l,output) 
    if m !=None: 
     print 'match found' 
相關問題