[IPython-dev] How to get the notebook name/path in the kernel?

Fernando Perez fperez.net@gmail....
Wed Feb 26 15:07:24 CST 2014


Konrad, Matthias' recent description is a great one: it's like asking a
book about the color of the eyes of its reader. That question is
fundamentally ill-posed, as multiple people may simultaneously read a book.

In IPython's case, the same applies: a kernel may be attached to a
notebook, but simultaneously to a terminal and a qtconsole. While we hold
fast on the idea that a notebook should only have *one* kernel, we've even
wondered if it could make sense to have multiple notebooks connected to an
single kernel (to operate on the same namespace while breaking up the
narrative into subdocuments more conveniently).

So I'm afraid that, by design, that question will remain one without a
well-defined answer...

You can probably write a magic that will call back out from the kernel to
the client JS and fetch the notebook path and would store it in a variable
in the user namespace, but my JS-fu isn't up to snuff to write that right
away. And you'd have to accept that it's a hack with potentially ambiguous
results (if for example we later allow multiple notebooks to connect to the
same kernel).

Cheers,

f


On Wed, Feb 26, 2014 at 10:11 AM, Thomas Kluyver <takowl@gmail.com> wrote:

> On 26 February 2014 09:35, Konrad Hinsen <konrad.hinsen@fastmail.net>wrote:
>
>> During initialization, my kernel needs to know the name and path of
>> the notebook that it is attached to.  I don't see an obvious way to
>> get this information.
>
>
> I don't think there is a good way to get that: the design is specifically
> that the kernel is an engine to run code, and should not know where that
> code is coming from.
>
> Thomas
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>


-- 
Fernando Perez (@fperez_org; http://fperez.org)
fperez.net-at-gmail: mailing lists only (I ignore this when swamped!)
fernando.perez-at-berkeley: contact me here for any direct mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20140226/a0079305/attachment.html 


More information about the IPython-dev mailing list