0

我在运行 python 脚本(由 ./waf --run 调用)时收到此错误:TypeError: abspath() 只需要 1 个参数(给定 2 个)

问题是它确实是用:obj.path.abspath(env) 调用的。

这不是 python 问题,因为该代码以前可以完美运行,并且它是一个巨大项目 (ns3) 的一部分,所以我怀疑它被破坏了。

但是,我的设置中一定发生了一些变化,因为这段代码以前有效,现在无效。

您能帮我弄清楚为什么会出现此错误吗?

这是python代码: http: //pastebin.com/EbJ50BBt。错误发生在第 61 行。

4

3 回答 3

2

该方法的文档Node.abspath()声明它不需要额外的env参数,我通过检查 git 历史确认它从未这样做过。我建议更换

if not (obj.path.abspath().startswith(launch_dir)
        or obj.path.abspath(env).startswith(launch_dir)):
    continue

if not obj.path.abspath().startswith(launch_dir):
    continue

如果这段代码以前工作过,这可能是由于or表达式的第一个运算符碰巧总是True,所以第二个运算符从未执行过。无论如何,这似乎是您的代码中的一个错误。

于 2012-07-06T11:08:00.180 回答
0

您应该在回溯中具有文件名和行号。转到该文件和行并找出“obj”和“obj.path.abspath”是。一个简单的解决方案是将违规行放在 try/except 块中以打印(或记录)更多信息,即:

# your code here
try:
    whatever = obj.path.abspath(env)
except Exception, e:
    # if you have a logger
    logger.exception("oops : obj is '%s' (%s)" % (obj, type(obj)))
    # else 
    import sys
    print >> sys.stderr, "oops, got %s on '%s' (%s)" % (e, obj, type(obj))
    # if you can run this code directly from a shell,
    # this will send you in the interactive debugger so you can
    # inspect the offending objet and the whole call stack.
    # else comment out this line
    import pdb; pdb.set_trace()

    # and re-raise the exception
    raise

我敢打赌,“obj.path”不是 python 的“os.path”模块,而“obj.path.abspath”是一个实例方法,它只接受“self”作为参数。

于 2012-07-06T10:23:39.550 回答
0

问题来自这样一个事实,显然 waf 不喜欢符号链接,python 代码不能为这种情况准备。

问题已解决,谢谢大家的帮助

于 2012-07-07T00:28:13.117 回答