ipython env

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Donald

    #1

    ipython env

    Anyone know what's up with environment variables when using ipython?

    When I type 'env' and hit return I get a dictionary full of useful
    information (trimmed for brevity):

    In [1]: env
    Out[1]:
    {'EDITOR': '/usr/bin/vim',
    [...]
    '_': '/Library/Frameworks/Python.framewor k/Versions/Current/bin/ipython',
    '__CF_USER_TEXT _ENCODING': '0x1F5:0:0'}


    But then when try to access the information in the dictionary it
    doesn't seem to exist:

    In [2]: env['EDITOR']
    ---------------------------------------------------------------------------
    exceptions.Name Error Traceback (most
    recent call last)

    /Users/destiney/<ipython console>

    NameError: name 'env' is not defined


    Thanks,


    --
    Greg Donald

  • Larry Bates

    #2
    Re: ipython env

    Greg Donald wrote:
    Anyone know what's up with environment variables when using ipython?
    >
    When I type 'env' and hit return I get a dictionary full of useful
    information (trimmed for brevity):
    >
    In [1]: env
    Out[1]:
    {'EDITOR': '/usr/bin/vim',
    [...]
    '_': '/Library/Frameworks/Python.framewor k/Versions/Current/bin/ipython',
    '__CF_USER_TEXT _ENCODING': '0x1F5:0:0'}
    >
    >
    But then when try to access the information in the dictionary it
    doesn't seem to exist:
    >
    In [2]: env['EDITOR']
    ---------------------------------------------------------------------------
    exceptions.Name Error Traceback (most
    recent call last)
    >
    /Users/destiney/<ipython console>
    >
    NameError: name 'env' is not defined
    >
    >
    Thanks,
    >
    >
    In Cpython you get this with:

    import os
    os.environ['EDITOR']

    -Larry

    Comment

    • Fernando Perez

      #3
      Re: ipython env

      Larry Bates wrote:
      Greg Donald wrote:
      >Anyone know what's up with environment variables when using ipython?
      [...]
      In Cpython you get this with:
      >
      import os
      os.environ['EDITOR']
      Yup, same in ipython :) Just to clarify, env is just a convenience function
      in ipython that simply does this:

      In [4]: env??
      Type: Magic function
      Base Class: <type 'instancemethod '>
      String Form: <bound method InteractiveShel l.magic_env of
      <IPython.iplib. InteractiveShel l object at 0x402046ec>>
      Namespace: IPython internal
      File: /home/fperez/usr/lib/python2.4/site-packages/IPython/Magic.py
      Definition: env(self, parameter_s='')
      Source:
      def magic_env(self, parameter_s='') :
      """List environment variables."""

      return os.environ.data


      Cheers,

      f

      Comment

      Working...