将新代码导入Jupyter Lab [英] Import new code into Jupyter Lab

查看:202
本文介绍了将新代码导入Jupyter Lab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些python函数导入Jupyter Lab笔记本中,然后在笔记本中使用它们.但是我要在对功能进行更改然后在Jupyter Lab笔记本中重新运行它们之间来回移动.我发现让Jupyter Lab使用更新的代码的唯一方法是重新启动内核,然后重新运行所有内容.虽然这可以正常工作,但有点麻烦,因为我需要再次在笔记本中运行所有内容.

I am importing some python functions into a Jupyter Lab notebook and then using them within the notebook. But I am going back and forth between making alterations to the functions and then rerunning them in the Jupyter Lab notebook. The only way I have found to get Jupyter Lab to use the updated code is to restart the kernel and then rerun everything. While this works fine, it is a bit cumbersome because I need to run everything in the notebook again.

是否有更好的方法允许Jupyter Lab看到导入函数中的新更改,同时仍保留所有先前设置的变量?

Is there a better way to allow Jupyter Lab to see the new changes in an imported function while still retaining all previously set variables?

推荐答案

您还可以通过将重装魔法放在笔记本中来使用重装魔法.它将自动重新加载代码.

You can also use the reload magic by placing this in your notebook. It will automatically reload code.

%reload_ext autoreload
%autoreload 2

这可能引起混乱的唯一时间是,如果实例化了一个对象,则更改代码,然后想知道为什么已实例化的对象不具有新功能.除了这种情况,它还可以很好地工作.

The only time this may cause confusion is, if you instantiated an object, change the code and then wonder, why the already instantiated object does not have the new functions. Besides this case, it works well.

这篇关于将新代码导入Jupyter Lab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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