Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python path separator [duplicate]

Tags:

python

path

Is there a proper platform-dependent (or independent?) path separator character somewhere in the Python standard library?

I am not asking about the directory separator / and \, but rather about the PATH separator: : and ;.

Java has java.io.File.pathSeparatorChar and java.io.File.pathSeparator to fulfill this need. Does Python have something similar? A fairly exhaustive search in os.path and pathlib docs yielded nothing, so I am beginning to lose hope.

I am not particularly hung up on the character itself. A function that behaves like os.path.join but for entire paths instead of path elements would be perfectly acceptable, preferable even.

like image 332
Mad Physicist Avatar asked Jun 11 '26 00:06

Mad Physicist


1 Answers

Maybe this is what you're looking for:

import os

os.pathsep

os.pathsep is : or ; while os.sep is \ or /.

like image 69
Cezar Cobuz Avatar answered Jun 12 '26 14:06

Cezar Cobuz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!