我正在makefile中设置一个环境变量(bash(,并且正在makefile的下一行执行python脚本。但是,当我尝试使用 python 脚本读取环境变量时os.environ.get()
我无法读取环境变量。实现这一目标的最佳方法是什么?
您需要
在同一行中导出它:
target:
export FOO=bar; python /the/script.py
或
target:
export FOO=bar;
python /the/script.py
以下内容适用于我的系统。
生成文件
ENVVAR=10
export ENVVAR
run:
python script.py
script.py
import os
print(os.environ.get('ENVVAR'))
运行:
$ ls
makefile script.py
$ make
python script.py
10