Quantcast
Channel: How to use export with Python on Linux - Stack Overflow
Viewing all articles
Browse latest Browse all 14

Answer by alex tingle for How to use export with Python on Linux

$
0
0

export is a command that you give directly to the shell (e.g. bash), to tell it to add or modify one of its environment variables. You can't change your shell's environment from a child process (such as Python), it's just not possible.

Here's what's happening when you try os.system('export MY_DATA="my_export"')...

/bin/bash process, command `python yourscript.py` forks python subprocess |_   /usr/bin/python process, command `os.system()` forks /bin/sh subprocess    |_      /bin/sh process, command `export ...` changes its local environment

When the bottom-most /bin/sh subprocess finishes running your export ... command, then it's discarded, along with the environment that you have just changed.


Viewing all articles
Browse latest Browse all 14

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>