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

Gökhan Sever gokhansever@gmail....
Tue Sep 21 13:24:56 CDT 2010


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)



-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20100921/8ef28abd/attachment.html 


More information about the IPython-User mailing list