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

Document how to import notebooks with Jupytext #159

Closed
mwouts opened this issue Jan 24, 2019 · 6 comments
Closed

Document how to import notebooks with Jupytext #159

mwouts opened this issue Jan 24, 2019 · 6 comments

Comments

@mwouts
Copy link
Owner

mwouts commented Jan 24, 2019

Jupytext makes it very simple to import the code a notebook into another notebook. All that is required is to save the notebook as a Python script, and import that script in the other notebook.

This is significantly simpler than the official example.

Also, and we should document this: Jupytext may help solve one issue people find with importing notebooks, that is: they do not want to import cells with plots or computations, but only those where functions or classes are defined.

Currently, it is possible to comment out a given cell in the Python representation by using either the 'frozen_cell' mode of the freeze extension (#101 ), or by setting an "active":"ipynb" cell metadata for that cell (#108)

@mwouts
Copy link
Owner Author

mwouts commented Jan 29, 2019

As documented above, with the freeze or active method we do have a way to comment out some cells in the Python representation.

But maybe commenting out the code is a bit too much... in some cases a if False: or if __main__ == "__main__": could be enough. And that would allow to apply the black reformatting (now an option in the new version 1.0) also to the frozen cells... @andrethrill, may I ask your advice on this?

@erdnaavlis
Copy link
Contributor

Hi @mwouts , I'm not sure I understand your two alternatives.

in some cases a if False: or if main == "main": could be enough.

if you adopt this one, would frozen cells code stop being commented in the .py files?

@mwouts
Copy link
Owner Author

mwouts commented Feb 4, 2019

Well, I'm not saying that's a change we should make, I just wanted to discuss that with you: rather than commenting out inactive python cells, we could indent them and prefix them with if False:.

The added value would be to make the resulting python file easier to refactor with editors or tools like black.

But that requires that the code in the frozen cell is syntaxically correct. Maybe that's not an assumption we want to make...

@erdnaavlis
Copy link
Contributor

Yes I understand. Thanks for the clarification.

But that requires that the code in the frozen cell is syntaxically correct. Maybe that's not an assumption we want to make...

Personally, that's something I sometimes don't have.... Code in my frozen cells, can be very, very, wrong. In many ways :)

@mwouts
Copy link
Owner Author

mwouts commented Feb 6, 2019

That's an useful remark, thanks @andrethrill !

mwouts added a commit that referenced this issue Feb 9, 2019
@mwouts
Copy link
Owner Author

mwouts commented Feb 10, 2019

The README now has a short paragraph on Importing Jupyter notebooks as modules.

@mwouts mwouts closed this as completed Feb 10, 2019
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

2 participants