Accessing variables from IPython interactive namespace in a script

前端 未结 2 752
借酒劲吻你
借酒劲吻你 2021-02-19 00:08

Is there an easy way to access variables in the IPython interactive namespace. While implementing a project that has a slow load command, I would like to run a script to load t

2条回答
  •  情歌与酒
    2021-02-19 01:10

    Try using the -i option on IPython's magic run command; it makes the script run using the current interactive namespace, e.g. with

    load.py:

    a = 5
    

    tst.py:

    print a
    

    From IPython I get;

    In [1]: from load import *
    
    In [2]: run -i tst
    5
    

提交回复
热议问题