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

Need a way to import from python script. #6628

Closed
ghost opened this issue Oct 5, 2014 · 2 comments
Closed

Need a way to import from python script. #6628

ghost opened this issue Oct 5, 2014 · 2 comments
Milestone

Comments

@ghost
Copy link

ghost commented Oct 5, 2014

Using ipython notebook --script saves a copy of the IPython notebook as a python script with the metadata of the cells ( I feel so ) preserved as comments.

I suggest that there should be a way to convert back to ipython notebook given this python script.

Use cases :

  • Direct operations / Modifications to the python script could be done as a whole file and restored back to the notebook.
  • Certain tools like autopep8 operate only on a python script. Hence the .ipynb ---> .py --autopep8--> .py ----> .ipynb should become feasible once this feature is included.

Also I need a small clarification ... When downloaded as a python file ( using the File --> Download as ) the contents are different compared to the python script generated using ipython notebook --script. Why is that so ? Only the latter seems to preserve the metadata in a disambiguous manner. The former method does not ( the commented metadata could as well be a regular comment )

@minrk
Copy link
Member

minrk commented Oct 5, 2014

Support for lossless roundtrip to .py files is not planned for support. In the next release, the --script flag is to be removed. The reason the output is different is also the reason --script is to be removed. --script was added when writing notebooks as Python was part of IPython.nbformat, and never actually wrote correct Python files. With the addition of nbconvert, this is no longer the case, and support for .py files is to be removed from IPython.nbformat. Download as uses nbconvert, which is the proper Python output of a notebook.

In the absence of --script, I do plan to add a more generic post-save hook, which could be used here.

@minrk minrk added this to the no action milestone Oct 5, 2014
@btel
Copy link
Contributor

btel commented Oct 28, 2015

@minrk is there a way to convert python .py script into notebook. I think this was the request in this issue. Round-tripping is not strictly necessary, but it would be nice feature anyway (running PEP8 checkers as suggested by @raghavrv being one use case and easy diffing/merging another),

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