when run from the command linethis value comes from whatever we've set the variable to in the shell itselfc:\pp \system\environmentset user=bob :\pp \system\environmentpython echoenv py echoenv hellobob when spawned by another script such as setenv py using the os system and os popen tools we met earlierthoughechoenv py gets whatever user settings its parent program has madec:\pp \system\environmentpython setenv py setenv bob echoenv hellobrian echoenv helloarthur ?gumby echoenv hellogumby :\pp \system\environmentecho %userbob this works the same way on linux in general termsa spawned program always inherits environment settings from its parents spawned programs are programs started with python tools such as os spawnvthe os fork/exec combination on unix-like platformsand os popenos systemand the subprocess module on variety of platforms all programs thus launched get the environment variable settings that exist in the parent at launch time from larger perspectivesetting shell variables like this before starting new program is one way to pass information into the new program for instancea python configuration script might tailor the pythonpath variable to include custom directories just before launching another python scriptthe launched script will have the custom search path in its sys path because shell variables are passed down to children (in factwatch for such launcher script to appear at the end of shell variable fine pointsparentsputenvand getenv notice the last command in the preceding example--the user variable is back to its original value after the top-level python program exits assignments to os environ keys are passed outside the interpreter and down the spawned programs chainbut never back up to parent program processes (including the system shellthis is also true in programs that use the putenv library calland it isn' python limitation per se this is by default some program-launching tools also let scripts pass environment settings that are different from their own to child programs for instancethe os spawnve call is like os spawnvbut it accepts dictionary argument representing the shell environment to be passed to the started program some os execvariants (ones with an "eat the end of their namessimilarly accept explicit environmentssee the os execcall formats in for more details script execution context