簡體   English   中英

類型錯誤:+ 不支持的操作數類型:“NoneType”和“str”

[英]TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

我有這行代碼

out_filename = os.path.join(self.save_dir, self.current_video + ".txt")

我收到以下錯誤:

trackHelper.export_last_video() 文件“C:\Users\Bharath\PointTrack\utils\mots_util.py”,第 130 行,在 export_last_video out_filename = os.path.join(self.save_dir, self.current_video + “.txt”) TypeError : + 不支持的操作數類型:'NoneType' 和 'str'

任何幫助都可以得到幫助。

您不能將字符串文字與 None 值連接起來,因此您需要確保self.current_video不返回 None。

作為預防措施,您始終可以檢查它是否返回 None 以外的任何其他值,然后進行連接。

您的self.current_video可能會返回None 你可以這樣做

if self.current_video is not None:
    out_filename = os.path.join(self.save_dir, self.current_video + ".txt")
else:
    # handle the case where self.current_video is None

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM