Load environment variables of bashrc into 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? 回答1: .bashrc should automatically be loaded into the environ on login import os print os.environ 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)