Home > Software design >  TypeError: unsupported operand type(s) for : 'NoneType' and 'str'
TypeError: unsupported operand type(s) for : 'NoneType' and 'str'

Time:01-04

I have this line of code

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

and I'm getting the following error:

trackHelper.export_last_video() File "C:\Users\Bharath\PointTrack\utils\mots_util.py", line 130, in export_last_video out_filename = os.path.join(self.save_dir, self.current_video ".txt") TypeError: unsupported operand type(s) for : 'NoneType' and 'str'

Any help could be appeciated.

CodePudding user response:

You cannot concatenate String literals with None values hence you need to make sure that self.current_video doesn't return None.

As a precaution, you could always check whether it returns any other value than None, and then do the concatenation.

CodePudding user response:

Your self.current_video might be returning None. You can do something like this

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
  • Related