0

Let say I want to set environment variable from a python script. For example PYTHONPATH.

On Windows it will be path1;path2;path3 (semicolon seperator).

On Linux it will be path1:path2:path3 (colon seperator).

Is there a cross-platform way to build the path using python?

petezurich
  • 7,683
  • 8
  • 34
  • 51
Elad Weiss
  • 3,402
  • 3
  • 19
  • 45

1 Answers1

2

The os module has a variable for just this purpose:

path = os.pathsep.join(path_elements)

os.pathsep is ':' or ';' depending on where you are running.

Ned Batchelder
  • 345,440
  • 70
  • 544
  • 649