您应该在回溯中具有文件名和行号。转到该文件和行并找出“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”作为参数。