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
Fix #1581 #1582
Fix #1581 #1582
Conversation
return IPython.nbformat.reads( | ||
s, IPython.nbformat.current_nbformat) | ||
else: | ||
nbformat_reads = IPython.nbformat.current.reads_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can’t you just use plain reads
on all versions?
nb_json = IPython.nbformat.reads(s)
seems to be enough on v2 and v3, at least according to the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you would have to import IPython.nbformat.current
and work with it all the time.
Here is a revised solution:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if IPython.version_info[0] >= 3:
nbformat_reads = lambda s: IPython.nbformat.reads(s)
else:
import IPython.nbformat.current
nbformat_reads = IPython.nbformat.current.reads_json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that reads()
requires a format as a second argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, it does. I was reading the wrong file.
nbformat_reads = lambda s: IPython.nbformat.reads(s, IPython.nbformat.current_nbformat)
I think this should work but have not tested it with IPython 2.0 yet... |
current_nbformat = nbformat.current_nbformat | ||
else: | ||
import IPython.nbformat.current as nbformat | ||
current_nbformat = 'json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be a Unicode string (u'json'
)? (I don't think it matters though, but have not really done much with unicode strings yet...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It already is Unicode:
from __future__ import unicode_literals, print_function
^^^^^^^^^^^^^^^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! It's work after I upgrade to IPython3.0.
Thanks!
Works fine with v2.3.1:
If it works with the current v3 dev:
Merging as soon as this is done. |
Shouldn't that be: Issue #1581?
|
Sure. |
👍 Thanks for your contribution! |
This adds a bit of code to deal with the API changes in the latest development version of IPython 3.0.0. Note: I read the notebook into the current format (as opposed to
nbformat.NO_CONVERT
) so that theHTMLExporter
can properly output the data. If the conversion is not done, then this will fail if there arecells
in the notebook as shown in the issue.There is probably more that could be cleaned up (the generated notebook for an initial post should probably use the current format rather than a hard-coded nbformat 3 template for example), but I wanted to keep this a minimal change to preserve backward compatibility.