Notebook: Dashboard based new file creation creates an Untitled.txt on top

Created on 16 Mar 2016  Â·  8Comments  Â·  Source: jupyter/notebook

Everytime I create a new notebook via the dashboard, it not only creates the new notebook file "Untitled.ipynb", but also "Untitled.txt".

Version: master (3feea618027713a53e540b6f7eb1e3abef57dc03)
Browser: Safari on OSX 10.10.5

Question

All 8 comments

Do you have a save hook configured? I could imagine this happening if you have configured it to replicate the old --script behaviour.

Oh yes, sorry forgot to mention that. I have exactly that configured.

Sent from my iPhone

On Mar 16, 2016, at 04:26, Thomas Kluyver [email protected] wrote:

Do you have a save hook configured? I could imagine this happening if you have configured it to replicate the old --script behaviour.

—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

But what's funny is that the .txt is created before I even ever save the notebook? That's how I thought it can't be related.

Sent from my iPhone

On Mar 16, 2016, at 04:26, Thomas Kluyver [email protected] wrote:

Do you have a save hook configured? I could imagine this happening if you have configured it to replicate the old --script behaviour.

—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

I think creating a notebook implicitly saves it as an empty file. Since the kernel hasn't yet started, the script save hook doesn't have the proper file extension to use, and the default is .txt. I'm not sure what a proper fix is, but the workaround might be to tweak the save hook function to skip saving if the script extension is .txt.

Hm, so I put some print statements into the save hook code to see what I get as os_path:

    global _script_exporter
    if _script_exporter is None:
        _script_exporter = ScriptExporter(parent=contents_manager)
    log = contents_manager.log

    base, ext = os.path.splitext(os_path)
    print('base:', base)
    print('ext:', ext)
    script, resources = _script_exporter.from_filename(os_path)

but I only get 1 print in the console when I create a new file, and that one already has the notebook extension:

[I 09:10:18.712 NotebookApp] Serving notebooks from local directory: /Users/klay6683/Dropbox/src/pyciss/notebooks
[I 09:10:18.713 NotebookApp] 0 active kernels
[I 09:10:18.713 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/
[I 09:10:18.713 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 09:10:24.418 NotebookApp] Creating new notebook in
base: /Users/klay6683/Dropbox/src/pyciss/notebooks/2016-03-16 Untitled
ext: .ipynb
[I 09:10:25.310 NotebookApp] Kernel started: 5e32e69f-da5a-4c5d-b25c-dfe49244fb0a

Maybe it is of importance that I adapted the Untitled creator like so?

import datetime as dt

c.ContentsManager.untitled_notebook = dt.date.today().isoformat() + ' Untitled'

After calling from_filename, check _script_exporter.file_extension. You can also get it from the notebook metadata:

nb.metadata.language_info.file_extension (use .get() appropriately, as the last two levels may not exist)

I don't think your modification to the Untitled name is likely to make a difference. Though if you keep notebook servers running for long periods, it will always give you the date when the notebook server was started, not necessarily the current date.

I worked around it with your help and put my solution here:
https://gist.github.com/michaelaye/c5303f55fc87d719e56e

thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Foadsf picture Foadsf  Â·  3Comments

ehossain1982 picture ehossain1982  Â·  3Comments

arbaazsama picture arbaazsama  Â·  3Comments

qnicole-zakka picture qnicole-zakka  Â·  3Comments

mmngreco picture mmngreco  Â·  3Comments