Is there a widget or keyboard shortcut to apply code formatting a jupyter notebook?
If I have a function like:
def f(x):
y = x*2
z = y*2
return z
Run Code Online (Sandbox Code Playgroud)
I'd like to be able to autotab this function over to:
def f(x):
y = x*2
z = y *2
return z
Run Code Online (Sandbox Code Playgroud)
automatically.
小智 5
Jupyter Nbextensions 配置器包含满足您的 Jupiter Notebook 需求的多个扩展:
您将在链接中找到有关如何设置它们的说明。这两个扩展都有可设置的工具栏按钮,并且适用于整个文档。
jupyter -black - Jupyter Notebook 和 Jupyter Lab 的简单扩展,可使用 Black 自动美化 Python 代码
对于 JupyterLab,还有JupyterLab_Black。
对于 JupyterLab,有jupyterlab_code_formatter - 一个 JupyterLab 插件,可以方便调用代码格式化程序。您可以为此配置键盘快捷键。
请记住,很快(现在是 2022 年秋季)以文档为中心的笔记本体验(现在大多数人都会联想到经典笔记本界面)将基于 JupyterLab 的底层,请参阅此处。因此,投入大量时间在旧的经典笔记本中解决问题可能会导致您需要尽快改变方法,因为许多仅适用于经典 Jupyter 笔记本界面的东西需要更新才能使用,而当前 JupyterLab 中已经可以使用的东西将需要更新。要么工作,要么更新的摩擦要少得多。
| 归档时间: |
|
| 查看次数: |
5075 次 |
| 最近记录: |