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?

justmayo
  • 41
  • 1
  • 6
  • 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 – Iain Shelvington Aug 18 '20 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). – alani Aug 18 '20 at 21:21
  • Does this answer your question? [Set shell environment variable via python script](https://stackoverflow.com/questions/38982640/set-shell-environment-variable-via-python-script) – blong Mar 22 '22 at 18:52

0 Answers0