0

I'm wanting to write a script in Python that contains an equivalent to these bash script lines

export something=some/file/path/name

But can't find a Python equivalent to export.

Any suggestions?

3
  • 2
    os.environ gives you access to the current processes environment as a dictionary. If you want to set an environment variable in your shell from inside a child Python process it's not possible Commented Aug 18, 2020 at 21:16
  • Per @IainShelvington's comment re the current process. Note also that this is a dictionary, so do os.environ['something']='some/file/path/name' Also note that variables that you set in the environment will be automatically inherited by child processes. In bash there is a distinction between variables that are exported and those that are not, but this doesn't really exist in Python (except perhaps that ordinary Python variables are not environment variables). Commented Aug 18, 2020 at 21:21
  • Does this answer your question? Set shell environment variable via python script Commented Mar 22, 2022 at 18:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.