- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试为机器人框架编写一个关键字,正如 @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 处理异常的方式。
如果您不想查看堆栈跟踪,请捕获异常并打印您想要的任何消息。
try:
check_IP()
except Exception as e
print str(e)
当然,如果您使用 check_IP
作为关键字,您将需要删除所有这些代码。
关于python - Python 的机器人框架关键字 : Error with unmatched string or IP. 如何解决此问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32759381/
我正在尝试运行此命令来进行一些清理。 egrep -v -f ref_file.css my_file.css 但是,它给了我一个错误。 egrep: 不匹配 ( 或\( 我该如何解决这个问题?我使用
我是 ksh 世界的新手,我现在遇到脚本问题。此行下的脚本位于 UNIX 机器中用户的 .profile 文件中,当我尝试连接他时,我总是得到错误 home/userTest/.profile: sy
我有包含时间的字符串,我想将时间格式化为 12 小时格式。 我试过了, pat1 = "(\d+):(\d+)?\s*pm" pat1 = "(\d+):(\d+)?\s*am" hooString
我刚刚在我的 sails 项目中添加了一个管理面板 Hook 。当我尝试升 sails 时出现此错误: warn: Sails' built-in layout support only works
我的公司有一款软件,代码库相当大。最近我被分配了一项任务,检查代码是否可以使用 gcc 4.1.2 在 x86_64 目标上编译。我对代码进行了非常小的修改,在编译过程中取得了相当大的进展,但就在今天
这是我的代码: String.prototype.escape = function(){ return this.replace(new RegExp("[\-\[\]\/\{\}\(\)\*\
我正在编写一个脚本来修复丢失的“F”问题。我在文件的第一行插入了一个缺失的“F”。该文件是日志文件,并不断更新新日志。但是,当我执行脚本时,出现以下错误:./s[37]: 第 39 行的语法错误:`/
我有 2 个表,我想从第一个表中检索 id_apartment 没有出现在第二个表中的行: id | id_floor | id_apartment ----+----------+---------
这个问题在这里已经有了答案: What special characters must be escaped in regular expressions? (13 个答案) 关闭 4 年前。 我写
我需要删除在 Twitter 消息中找到的所有 URL。我有一个包含大约 200,000 条此类消息的文件,因此速度至关重要!为此,我使用 Java 作为编程语言,这是我的代码示例: public S
我的 fragment 中有一个 EditText,当我执行输入或任何类似输入的操作时,我想做一些事情。但是我在 KeyEvent 或 actionId 的 onEditorAction id 上遇到
让 m类型为 std::smatch .假设有一个不匹配的组 i .什么是m.position(i) ?就此而言,什么是m[i] ? 例如,考虑 std::regex re {"^(a+)|(b+)"
可重现的示例: package test; import java.io.FileOutputStream; import java.io.ObjectOutputStream; import jav
我定义了一个模式,当我在字符串上匹配它时,它会显示错误:不匹配的右括号,但前提是我将\添加到支持 Windows。 Grok 过滤器应该匹配这样的字符串:日志\01.01.2018\1_00_06\s
我有一个包含以下格式数据的文件: {"parameter":"toto.tata.titi", "value":"0/2", "notif":"1"} 我使用 sed 对文件进行了更改: sed -i
我有一个shell脚本,当我执行它的时候,我得到了错误 syntax error at line 34 : `<<' unmatched in ksh script column_name=`sqlp
我是 Phoenix 和网络套接字的新手。我正在尝试使用 Web Sockets 创建一个应用程序,但 Phoenix 说忽略 Protsci.UserSocket 中不匹配的主题“analysis:
我正在使用 Postgres db 在 Docker 中运行 Wagtail 2.4,当我尝试在 Wagtail 中编辑博客文章时出现错误。最初的帖子有效,我可以在网站上正常查看页面。当我在 Wagt
您好,我正在尝试编写一个程序,如果感兴趣的人在给定时间上线,该程序将提醒用户。到目前为止我的程序是 #!/usr/bin/ksh message="" when="" validFiles="" va
在我的同位素网格中,我想同时显示匹配和不匹配的元素,而不匹配的元素不会消失。相反,我希望不匹配的元素具有 0.7 的不透明度。 关于 Isotope website他们概述了隐藏元素的 CSS 类,所
我是一名优秀的程序员,十分优秀!