How to use IPython magic within a script to auto r

2019-06-09 09:12发布

I am trying to include some of the IPython built-in magic functions to auto reload modules when I am running a script. So I have tried this:

if __IPYTHON__:
    %load_ext autoreload
    %autoreload 2

But IPython returns:

%load_ext autoreload
^
SyntaxError: invalid syntax

Any idea how to solve this?

1条回答
放荡不羁爱自由
2楼-- · 2019-06-09 09:51

Thank you for the link Gall!!! Whit your help I came up with the following solution:

from IPython import get_ipython
ipython = get_ipython()

if '__IPYTHON__' in globals():
    ipython.magic('load_ext autoreload')
    ipython.magic('autoreload 2')
查看更多
登录 后发表回答