Jump to content

Append path to environment variable


Recommended Posts

How to add a new path to environment variable?
For example, trying to add a new path to the "PATH" (i need HOUDINI_PATH indeed):

import os
print os.environ['PATH']
os.environ['PATH'] = 'C:/TEMP;&'
print os.environ['PATH']

>> C:\Program Files\Microsoft MPI\Bin\;C:\Program Files\Java\jdk-10.0.1\bin; ...

>> C:/TEMP;&

So, os.environ['PATH'] = 'C:/TEMP;&' overwrites existing "PATH" variable.
This way os.environ['PATH'] += os.pathsep + 'C:/TEMP;' is working.

I was thinking "&" should do the trick (append a string to the variable instead of replacing it), but it does not work. So I wonder if I misunderstood something with "&" and "+=" is the only solution.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...