Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 250
ChrisB Avatar asked Apr 16 '26 07:04

ChrisB


1 Answers

.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))
print env
like image 76
Joran Beasley Avatar answered Apr 17 '26 20:04

Joran Beasley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!