[IPython-dev] 2to3 for IPython Notebook

Thomas Kluyver takowl at gmail.com
Sun Nov 3 12:14:53 EST 2013


On 3 November 2013 01:17, Raniere Silva <ra092767 at ime.unicamp.br> wrote:

> I need to convert some Python2 `print` statements to Python3 `print`
> function
> in .ipynb files. `2to3` didn't work. What tool I can use?
>


Copying my comment from the Software Carpentry Github thread here:
https://github.com/swcarpentry/bc/issues/107

We don't have an automated conversion tool for notebooks ourselves - we
don't curate enough notebooks ourselves to really need one. However, it
should be feasible to write something that loads a notebook, runs 2to3 on
each of the code cells, and saves it again. I'm happy to help build that.
It's not entirely trivial, though:

   - Some changes should only be done once per notebook, e.g. adding from
   __future__ imports.
   - IPython special syntax, e.g. %magics might break the parser 2to3 is
   using.

Thanks,

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20131103/b66c7e55/attachment.html>


More information about the IPython-dev mailing list