How to capture all the environment variables from shell?

Discussion in 'Python' started by Peng Yu, Jul 27, 2010.

  1. Peng Yu

    Peng Yu Guest

    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'

    --
    Regards,
    Peng
    Peng Yu, Jul 27, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RC
    Replies:
    4
    Views:
    8,012
    Tor Iver Wilhelmsen
    Jul 12, 2005
  2. Gerard Flanagan
    Replies:
    2
    Views:
    464
    Gerard Flanagan
    Mar 14, 2007
  3. Replies:
    14
    Views:
    1,101
  4. Lee
    Replies:
    1
    Views:
    317
  5. Tim Chase
    Replies:
    3
    Views:
    258
    Steven W. Orr
    Aug 10, 2010
Loading...

Share This Page