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

Fernando Perez fperez.net@gmail....
Tue Sep 21 16:20:07 CDT 2010

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

More info:

In [3]: _ip.to_user_ns?
Type:           instancemethod
Base Class:     <type 'instancemethod'>
Namespace:      Interactive
Definition:     _ip.to_user_ns(self, vars, interactive=True)
    Inject a group of variables into the IPython user namespace.


     - vars: string with variable names separated by whitespace, or a
     dict with name/value pairs.

     - interactive: if True (default), the var will be listed with
    %whos et. al.

    This utility routine is meant to ease interactive debugging work,
    where you want to easily propagate some internal variable in your code
    up to the interactive namespace for further exploration.




More information about the IPython-User mailing list