简体   繁体   English

使用 VSCode 时获取 Jupyter 笔记本名称

[英]Get Jupyter notebook name while using VSCode

I'm trying to get the path of the current Jupyter notebook, while using VSCode.我正在尝试获取当前 Jupyter 笔记本的路径,同时使用 VSCode。

I tried all of the solutions in this post but none of them are working in VSCode.我尝试了这篇文章中的所有解决方案,但没有一个在 VSCode 中工作。 I can get them to work through Jupyterlab.我可以让他们通过 Jupyterlab 工作。

When I try the solutions that involve a %%javascript magic command, that cell will execute successfully, but the kernel is not updated with the variable containing the notebook name.当我尝试涉及 %%javascript 魔术命令的解决方案时,该单元格将成功执行,但 kernel 未使用包含笔记本名称的变量进行更新。

If you know the current opened notebook's filename, how about trying this method:如果你知道当前打开的笔记本的文件名,试试这个方法怎么样:

import os
notebook_path = os.path.abspath("a.ipynb")
print(notebook_path)

在此处输入图像描述

Please try with this fix.请尝试使用此修复程序。 This fix may vary from OS to OS.此修复程序可能因操作系统而异。 Follow me for more GitHub LinkedIn关注我了解更多GitHub LinkedIn

import os
os.path.basename(globals()['__vsc_ipynb_file__'])

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM