The os.path.join(a, b) method will generate a string ending without ‘/’ no matter it is a file or directory. Now, is there any way (or any other os.path method) to get a ‘/’ automatically for the case of the directory?
The os.path.join(a, b) method will generate a string ending without ‘/’ no matter it
Share
There is no such function in
os.path. It’s easy to code up yourself, though:This will add a
/if there isn’t already one at the end ofpathin case it points to a directory.