0
$\begingroup$

According to the docs for bpy.path.basename:

Equivalent to os.path.basename, but skips a “//” prefix.

Use for Windows compatibility.

But on Windows, I don't see any difference between it and os.path.basename.

Are there any cases where the two functions will give different output?

$\endgroup$
0
$\begingroup$

os.path.basename doesn't understand Blender's // prefix (denoting a path relative to the current blend file). bpy.path.basename does understand this. If your path is (or could be) a blend-file-relative path, use the bpy.path.* functions.

On Linux I don't see any difference either, don't have Windows handy at the moment to check there.

$\endgroup$
  • 1
    $\begingroup$ So the only edge case I was able to find was os.path.basename('//dir/file.txt') gives '' instead of 'file.txt'. os.path.basename('//dir/dir2/file.txt') and os.path.basename('//file.txt') both work correctly. $\endgroup$ – Isaac Nov 12 '17 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.