如何在脚本中使用IPython magic来自动重装模块? [英] How to use IPython magic within a script to auto reload modules?

查看:286
本文介绍了如何在脚本中使用IPython magic来自动重装模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在运行脚本时将一些IPython内置魔术函数包含在自动重装模块中。所以我试过这个:

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

但IPython返回:

But IPython returns:

%load_ext autoreload
^
SyntaxError: invalid syntax

任意想法如何解决这个问题?

Any idea how to solve this?

推荐答案

感谢您的链接Gall !!!在你的帮助下,我想出了以下解决方案:

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')

这篇关于如何在脚本中使用IPython magic来自动重装模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆