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
  • 9,280
  • 9
  • 43
  • 57
Elad Weiss
  • 3,662
  • 3
  • 22
  • 50

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
  • 364,293
  • 75
  • 561
  • 662