TypeError:不支持的操作数类型为+:'NoneType'和'str'使用GITPYTHON
问题描述:
我正在使用gitpython来做一些文件处理。一切工作正常,除了d.new_file条件,我遇到这种类型的错误,我不能连接NoneType和str在一起。TypeError:不支持的操作数类型为+:'NoneType'和'str'使用GITPYTHON
我认为d.a_path是无,但我不明白为什么它不工作,但它在其他条件下工作。
for d in repo.head.commit.diff(None,create_patch=True):
if d.deleted_file:
print("deleted file")
elif d.new_file:
print(" new_file")
with open(main_dir,'a+') as main_file:
main_file.write(d.a_path +'\n')
elif d.renamed_file:
print("renamed file")
else:
print(" modified file")
with open(main_dir,'a') as main_file:
main_file.write(d.a_path+"\n")
handle_diff(d.diff)
有人知道为什么d.a_path为None为d.new_file条件?
答
There are a few cases where None has to be expected as member variable value:
New File:
a_mode is None a_blob is None a_path is NoneDeleted File:
b_mode is None b_blob is None b_path is None
新文件的路径应该是b_path
一个新的文件,而不是在a_path
,因为文件并未a
存在。