如何在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
相關文章
相關標籤/搜索