[IPython-User] Populating variables in current frame automatically?

Francesc Alted faltet@pytables....
Wed Sep 22 01:46:55 CDT 2010


A Tuesday 21 September 2010 23:20:07 Fernando Perez escrigué:
> On Tue, Sep 21, 2010 at 8:21 AM, Francesc Alted <faltet@pytables.org> 
wrote:
> > I'd like to know if there is a good way to automatically import
> > items in a dictionary as variables into an IPython shell.  For
> > example, I'd like to do something like:
> > 
> > In [1]: mydict = {'p1': 1, 'p2':2}
> 
> In [4]: mydict = {'p1': 1, 'p2':2}
> 
> In [5]: p1
> ---------------------------------------------------------------------
> ------ NameError                                 Traceback (most
> recent call last)
> 
> /home/fperez/ipython/ipython/<ipython console> in <module>()
> 
> NameError: name 'p1' is not defined
> 
> In [6]: _ip.to_user_ns(mydict)
> 
> In [7]: p1
> Out[7]: 1

Nice.  I knew that IPython would have a solution for this, but it is not 
always obvious to found it.  Thanks Fernando!

-- 
Francesc Alted


More information about the IPython-User mailing list