如何在Python中设置环境变量 - How to set environment variables in Python

问题:

I need to set some environment variables in the python script and I want all the other scripts that are called from python (shell scripts) which will be child process to see the environment variables set. 我须要在python脚本中设置一些环境变量,而且我但愿从python调用的全部其余脚本(shell脚本)(将是子进程)来查看设置的环境变量。 The value is a number. 该值为数字。 python

If I do os.environ["DEBUSSY"] = 1 , it complains saying that 1 has to be string. 若是我作os.environ["DEBUSSY"] = 1 ,它抱怨说1必须是字符串。 I also want to know how to read the environment variables in python (in the later part of the script) once I set it. 我还想知道一旦设置好如何在python(在脚本的后半部分)中读取环境变量。 shell


解决方案:

参考一: https://stackoom.com/question/P3PU/如何在Python中设置环境变量
参考二: https://oldbug.net/q/P3PU/How-to-set-environment-variables-in-Python
相关文章
相关标签/搜索