Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path Separator in Python 3

I have two strings:

C:\Data

and another folder

Foo1

I need, the windows output to be

C:\Data\Foo1

and the Linux output to be

/data/foo1

assuming /data is in linux. Is there any constant separator that can be used in Python, that makes it easy to use irrespective of underlying OS?

like image 870
Romaan Avatar asked Nov 30 '22 04:11

Romaan


1 Answers

Yes, python provides os.sep, which is that character, but for your purpose, the function os.path.join() is what you are looking for.

>>> os.path.join("data", "foo1")
"data/foo1"
like image 164
Gareth Latty Avatar answered Dec 06 '22 21:12

Gareth Latty