python - 使用 os.path.join() 运行脚本时出现 TypeError
问题描述
我正在运行的脚本中有以下几行:
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
在我看来,这就像一个简单的加入然后替换,不知道为什么会失败。
解决方案
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
推荐阅读
- javascript - Ajax URL 似乎被公司防火墙阻止
- matlab - 确定毛孔的性质
- laravel - 如何在加入 laravel 时从具有不同 id 的同一张表中检索不同的名称
- r - 如何从倒置的钟形曲线中采样
- docker - 带有运行命令的docker文件未执行
- c# - 不存在从对象类型 System.Windows.Forms.DataGridViewTextBoxCell 到已知托管提供程序本机类型的映射
- javascript - 如何通过Javascript检查iOS.12.2+中的运动/方向permissionState?
- python-3.x - 无法在 VSCode 上的 Jupyter 笔记本中使用 cx_Oracle 进行连接
- javascript - 如何解释 Observable.of(Math.random()) 总是返回相同的值?
- scala - Spark 2.3:减去数据帧但保留重复值(Scala)