jupyter notebook快捷打开文件所在目录
时间: 2023-10-11 19:09:30 浏览: 71
3. Windows版本的Jupyter Notebook如何修改启动时的默认文件路径.pdf
可以使用以下代码在 Jupyter Notebook 中快捷打开文件所在目录:
```python
import os
from notebook.notebookapp import list_running_servers
def open_browser_to_notebook_directory():
"""
Open the user's browser to the directory of the current notebook.
"""
try:
# Get the server info for the current notebook
server_info = list_running_servers()[0]
base_url = server_info['url']
notebook_path = os.getcwd().replace(os.getenv('HOME'), '')
notebook_url = base_url + 'tree' + notebook_path
# Open the notebook directory in the default web browser
import webbrowser
webbrowser.open(notebook_url)
except Exception as e:
print("Error opening browser:", e)
```
阅读全文