How to capture all the environment variables from shell?

P

Peng Yu

Hi,

R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm
not sure what it does when os module is imported. But it seems that
os.environ doesn't capture all the environment variable from the
shell. Could anybody let me know what is the correct way to inherent
all the environment variables form the shell?

$ echo $R_HOME
/opt/R-2.11.1
$ cat main.py
#!/usr/bin/env python

import os

print os.environ['R_HOME']
$ ./main.py
Traceback (most recent call last):
File "./main.py", line 5, in <module>
print os.environ['R_HOME']
File "/opt/Python-2.6.5/lib/python2.6/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: 'R_HOME'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top