'Python optparse: parse.error()---->TypeError: error() missing 1 required positional argument: 'msg'' Python optparse:parse.error()---->TypeError:error()缺少1个必需的参数:'msg'

2024-06-16 12:00:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我在新的python3.4.3上运行这个跟踪路由模块时遇到了问题。在python的早期版本中,我能够运行该模块,但现在我无法运行。当我尝试调用optparse的parser.error()函数时,我一直收到这个回溯错误。在

TypeError: error() missing 1 required positional argument: 'msg'* 

这是我的代码片段

^{pr2}$

错误总是出现在“if”语句中

if len(args) != 1:
    parser.error()

然后我试了这个

if len(args) != 1:
    parser.error("Incorrect number of arguments")

当我这次尝试运行模块时,我收到了这个错误

  Usage: TraceRoute.py [options] hostname 
  TraceRoute.py: error: Incorrect number of arguments

我希望得到一些关于如何修复此代码以防止此错误的反馈,以及关于如何在Python3.4.3中正确使用optparse库的更多信息


Tags: 模块of代码pyparsernumberlenif