How to set environment variables in Python?

前端 未结 11 1937
情话喂你
情话喂你 2020-11-22 04:00

I need to set some environment variables in the Python script and I want all the other scripts that are called from Python to see the environment variables\' set.

If

11条回答
  •  醉梦人生
    2020-11-22 04:38

    When you play with environment variables (add/modify/remove variables), a good practice is to restore the previous state at function completion.

    You may need something like the modified_environ context manager describe in this question to restore the environment variables.

    Classic usage:

    with modified_environ(DEBUSSY="1"):
        call_my_function()
    

提交回复
热议问题