3 回答

TA贡献1864条经验 获得超2个赞
我注意到上面的评论并想注意你不会用 print() 捕捉到 None 类型:
这样做:
>a = None
>print(a)
将输出None到控制台。
我会遵循给出的尝试捕捉错误的建议。你甚至可以做一个简单的检查。
代替:
f1 = open(filethub)
你可以这样做:
if filethub:
f1 = open(filethub)
但是对整个底部部分进行尝试捕获可能会更好,并且它几乎必须遍历脚本的整个下部。您甚至可以记录错误文件以供以后查看。

TA贡献1806条经验 获得超5个赞
似乎错误在返回 NoneType 的 find 函数中,但我不知道为什么
通过在 find 函数中添加print(type(filethub))打开文件和打印语句之前找到。
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
heres your problem
<class 'NoneType'>
Traceback (most recent call last):
File "./line_diff.py", line 90, in <module>
main()
File "./line_diff.py", line 34, in main
f1 = open(filethub)
TypeError: expected str, bytes or os.PathLike object, not NoneType

TA贡献1836条经验 获得超5个赞
错误消息告诉我们
open
使用参数调用None
。参数来自
filethub
,所以filethub
是None
。最后一次
filethub
分配是由find
函数分配的。所以,
find
函数返回None
。
你没有包含这个find
功能,所以我不能说为什么。但是您可能需要检查是否find
返回None
,如果是,则继续下一次迭代。
添加回答
举报