简体   繁体   English

如何检查哪个 Jupyter notebook 已经“%run”了另一个 notebook?

[英]How do I check which Jupyter notebook has “%run” another notebook?

I have a Jupyter notebook( parent.ipynb ) which runs another notebook( child.ipynb ) inside it.我有一个 Jupyter 笔记本( parent.ipynb ),它在里面运行另一个笔记本( child.ipynb )。

Is there a way to get the filename of the parent file from inside the child file?有没有办法从子文件中获取父文件的文件名? My child file has a logger and therefore can be called by multiple files.我的子文件有一个记录器,因此可以被多个文件调用。 It needs to know which file is calling the logger to create log records and therefore I was wondering if there is any magic or any sort of method that can help me with this.它需要知道哪个文件正在调用记录器来创建日志记录,因此我想知道是否有任何magic或任何类型的方法可以帮助我解决这个问题。

Basically,基本上,

A.ipynb A.ipynb

[1] %run B.ipynb

B.ipynb B.ipynb

-- insert code that can print parent filename when called --

add header inside the parent file as follow:在父文件中添加 header 如下:

import child

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

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