9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Jupyter notebookのnotebook名を取得する

Last updated at Posted at 2019-06-17

TL; DR

jsを経由してnotebook名を取得する

%%javascript
var notebook_name = document.body.attributes['data-notebook-name'].value
IPython.notebook.kernel.execute(`NOTEBOOK_NAME = '${notebook_name}'`);

もう一つの方法

上の方法ではnotebook内にjsが混じってしまって統一感がないので,pythonで完結する方法も紹介する

1. iPythonのkernel idを取得する

import re
from IPython.lib import kernel

conn_file = kernel.get_connection_file().split('/')[-1]
kernel_id = re.findall('kernel-(.*)\.json', conn_file)[0]

2. session一覧を取得する

url: http://{jupyter_host}/api/sessions
* tokenやpasswordでログインしたcookieが必要

3. kernel idが一致するsessionを探してファイル名を取得する

9
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?