gpt4 book ai didi

python - 如何在脚本中使用 IPython 魔法来自动重新加载模块?

转载 作者:行者123 更新时间:2023-12-04 16:09:38 25 4
gpt4 key购买 nike

我试图在运行脚本时包含一些 IPython 内置魔法函数来自动重新加载模块。所以我试过这个:

if __IPYTHON__:
%load_ext autoreload
%autoreload 2

但 IPython 返回:
%load_ext autoreload
^
SyntaxError: invalid syntax

知道如何解决这个问题吗?

最佳答案

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

from IPython import get_ipython
ipython = get_ipython()

if '__IPYTHON__' in globals():
ipython.magic('load_ext autoreload')
ipython.magic('autoreload 2')

关于python - 如何在脚本中使用 IPython 魔法来自动重新加载模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com