Kalina
Kalina

Reputation: 5594

Python directory structure on Windows vs Linux

I am writing a Python script on Windows, that needs to work on a Red Hat Linux machine. On Windows,

os.path.abspath(os.curdir)

returns something like

C:\Users\Me\...\CurrentDirectory

without a trailing \ .

I'm unable to run it on Linux, but to my knowledge it would be more like

/home/Me/.../CurrentDirectory

with the slashes going the other way, and I'm uncertain about a trailing / . First of all, is there one? Secondly, how do I deal with this issue? The script doesn't have to work on both Windows and Linux, just Linux, in the end. Though I can only test it on Windows :(

Upvotes: 1

Views: 2565

Answers (2)

armandino
armandino

Reputation: 18548

It shouldn't matter if you use os.path.join()

See:

Upvotes: 3

Adithya Surampudi
Adithya Surampudi

Reputation: 4454

The behavior would be more or less the same across the OS. Instead of using \ or / use

 os.sep

inside your code. Do not try to hardcode anything

Upvotes: 2

Related Questions