使用运行脚本时获取TypeError操作系统路径连接()

2024-04-16 16:27:20 发布

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

我正在运行的脚本中有以下行:

api_xml = os.path.join(opts.out, os.path.basename(
    opts.api_raw).replace('.raw', '.xml'))

运行Python 3.7时,出现以下错误:

Traceback (most recent call last):
  File "generate_code.py", line 32, in <module>
    opts.api_raw).replace('.raw', '.xml'))
  File "/usr/lib/python3.7/posixpath.py", line 146, in basename
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

在我看来,这就像一个简单的连接,然后取代,不知道为什么它是失败的。你知道吗


Tags: pathinpy脚本apirawosline
1条回答
网友
1楼 · 发布于 2024-04-16 16:27:20
TypeError: expected str, bytes or os.PathLike object, not NoneType

意味着您将None传递给需要路径的函数。你知道吗

在尝试构建api_xml之前,请尝试添加以下行:

assert opts.out is not None
assert opts.api_raw is not None

相关问题 更多 >