[IPython-User] Populating variables in current frame automatically?
Francesc Alted
faltet@pytables....
Wed Sep 22 01:45:05 CDT 2010
A Tuesday 21 September 2010 20:24:56 escriguéreu:
> On Tue, Sep 21, 2010 at 10:21 AM, Francesc Alted
<faltet@pytables.org>wrote:
> > Hi,
> >
> > 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 [2]: import sys
> >
> > In [3]: frame= sys._getframe(0)
> >
> > In [4]: frame.f_locals.update(mydict)
> >
> > In [5]: p1
> > Out[5]: 1
> >
> > In [6]: p2
> > Out[6]: 2
> >
> > but seems a bit ugly to my eyes :-/
> >
> > I don't want to use the %store magic because I may want to use
> > different (potentially pickled) dictionaries in order to populate
> > my variables.
>
> They say it is dangerous to update locals() directly, but for the
> sake of practicality:
>
> locals().update(mydict)
Hmm, that's better than my solution. Thanks!
--
Francesc Alted
More information about the IPython-User
mailing list