Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read notebooks from python scripts? #128

Closed
mwouts opened this issue Jul 19, 2018 · 4 comments
Closed

How to read notebooks from python scripts? #128

mwouts opened this issue Jul 19, 2018 · 4 comments
Milestone

Comments

@mwouts
Copy link
Contributor

mwouts commented Jul 19, 2018

I know I can save notebooks as python scripts using nbformat.v3.nbpy, and that I can open them again as python notebooks.

I'd like to go further, and open arbitrary python scripts as notebooks. Recently I've been working on a proof of concept at nbsrc. The main difficulty in doing that seems to define a natural and robust format for notebooks as python scripts. Current format is documented here.

Could you please share your experience on this? I'd be glad to have your feedback on the text format drafted in previous link. Also, I was wondering why nbpy had not been ported to v4. Thanks!

@mwouts
Copy link
Contributor Author

mwouts commented Jul 19, 2018

I forgot to mention that the question is related to jupyter/notebook#3694 (originally on how to read notebooks from R markdown, but reading from python might be very useful as well).

@takluyver
Copy link
Member

After notebook format version 3, we dropped the notion of saving notebooks in different kinds of file using nbformat, and made JSON the only supported format. Now if people want to plug in a different way to store notebooks, they usually do that at the 'content manager' level in the notebook server.

If you want to write your own code to read another kind of file, it's very easy to use nbformat to construct a notebook object: http://nbformat.readthedocs.io/en/latest/api.html#module-nbformat.v4

@mwouts
Copy link
Contributor Author

mwouts commented Jul 19, 2018

Hi @takluyver , yes certainly, that's what we have been doing (providing a contents manager) in the nbrmd / nbsrc projects, and it works quite well indeed.

My question was more about your previous experience on how to design a good representation of notebooks as python scripts, how to make sure that generic python files open well in jupyter, and that round trip convertion preserves inputs, etc., but I see that nbpy dates back from 2015 already, so I understand that it was a while ago!

By the way, the documentation you cite seems to answer another question I had - whether there is a standard cell metadata for hidding cell input/ output (jupyter/notebook#3700). Apparently source_hidden and outputs_hidden are the coming standard, I am correct?

@mwouts
Copy link
Contributor Author

mwouts commented Sep 1, 2018

Thanks @takluyver for the updates. Since then, I have developed jupytext that reads/writes python scripts from Jupyter notebooks, so I'll close this issue. The tool has started working fairly well, but in case you have one instant for this, any feedback on the file format is warmly welcome!

@mwouts mwouts closed this as completed Sep 1, 2018
@MSeal MSeal added this to the 5.0 milestone Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants