我想做一個模式搜索,如果匹配,然後設置計數器值bitarray。python正則表達式錯誤
runOutput = device[router].execute (cmd)
runOutput = output.split('\n')
print(runOutput)
for this_line,counter in enumerate(runOutput):
print(counter)
if re.search(r'dev_router', this_line) :
#want to use the counter to set something
得到以下錯誤:
if re.search(r'dev_router', this_line) :
2016-07-15T16:27:13: %ERROR: File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/re.py", line 166,
in search 2016-07-15T16:27:13: %-ERROR: return _compile(pattern, flags).search(string)
2016-07-15T16:27:13: %-ERROR: TypeError: expected string or buffer
然後計數器可以是這樣簡單的:在循環'counter = 0'之前,並且如果匹配'counter + = 1' –