ipython env

G

Greg Donald

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.framework/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.NameError Traceback (most
recent call last)

/Users/destiney/<ipython console>

NameError: name 'env' is not defined


Thanks,
 
L

Larry Bates

Greg said:
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.framework/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.NameError 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
 
F

Fernando Perez

Larry said:
Greg said:
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 InteractiveShell.magic_env of
<IPython.iplib.InteractiveShell 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
 

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
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top