本文介绍了将bashrc的环境变量加载到python中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spyder设置.bashrc的环境变量;换句话说,我正在寻找读取我的.bashrc的python命令.有什么主意吗?

I'm trying to set the environment variable of my .bashrc using Spyder; in other words I'm looking for a python command that reads my .bashrc. Any idea?

推荐答案

.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

这篇关于将bashrc的环境变量加载到python中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 05:13