【发布时间】:2015-09-24 10:45:30
【问题描述】:
我正在尝试为机器人框架编写一个关键字,正如@Brayan Oakley 在问题中所建议的那样:
How to write python function to test the matched strings (to use for Robot framework keyword)?
我的 Python 文件:
import os,re
def check_IP():
cmd = ' netstat -ano '
output = os.popen(cmd).read()
match1 = re.findall('.* (1.1.1.1).*',output)
mat1 = ['1.1.1.1']
if match1 == mat1:
print "IP addr found"
if match1 != mat1:
raise Exception('No matching IP...')
check_IP()
我正在尝试匹配“netstat -ano”命令中的 IP 地址。如果匹配,我会按预期收到“找到 IP 地址”消息。
但如果没有找到 IP 地址,我会按预期收到异常,但会显示以下错误消息。
C:\Users\test\Desktop>python check.py
Traceback (most recent call last):
File "check.py", line 13, in <module>
check_IP()
File "check.py", line 11, in check_IP
raise Exception('No matching IP...')
Exception: No matching IP...
C:\Users\test\Desktop>
请问有什么解决办法吗?
【问题讨论】:
标签: python python-2.7 robotframework