How to set environment variables in Python?

前端 未结 11 1942
情话喂你
情话喂你 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:33

    Environment variables must be strings, so use

    os.environ["DEBUSSY"] = "1"
    

    to set the variable DEBUSSY to the string 1.

    To access this variable later, simply use:

    print(os.environ["DEBUSSY"])
    

    Child processes automatically inherit the environment variables of the parent process -- no special action on your part is required.

提交回复
热议问题