Why can't environmental variables set in python persist?

前端 未结 7 779
南旧
南旧 2020-11-27 03:55

I was hoping to write a python script to create some appropriate environmental variables by running the script in whatever directory I\'ll be executing some simulation code,

7条回答
  •  再見小時候
    2020-11-27 04:37

    If you set environment variables within a python script (or any other script or program), it won't affect the parent shell.

    Edit clarification: So the answer to your question is yes, it is true. You can however export from within a shell script and source it by using the dot invocation

    in fooexport.sh

    export FOO="bar"
    

    at the command prompt

    $ . ./fooexport.sh
    $ echo $FOO
    bar
    

提交回复
热议问题