且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将bashrc的环境变量加载到python中

更新时间:2023-12-02 19:54:40

.bashrc应该在登录时自动加载到环境中

.bashrc should automatically be loaded into the environ on login

import os

print os.environ

如果您想从bash源文件中创建值字典,理论上您可以做类似的事情

if you wanted to create a dictionary of values from a bash source file you could in theory do something like

output = subprocess.check_output("source /path/to/.bashrc;env")
env = dict(line.split("=") for line in output.splitlines() if "=" in line))
print env