4

Because of SciPy, I have stuck with Python 2 even though I would like to move to Python 3. As most of my research work is data analysis and modelling, I have used the IPython HTML notebook in my day-to-day work. However, that means I've become used to the Python 2 syntax (e.g. print x), which frequently comes up in my sanity-checking steps.

Now that SciPy seems to be Python 3-compatible (please correct me if I'm wrong), I'd like to migrate over from Python 2 to Python 3.

However, that means most of my IPython notebooks will be riddled with Python 2 print statements, which will yield tons of errors each time I re-run analyses through them.

So here's my question: Is 2to3 capable of modifying the IPython HTML notebooks? Logistical challenge: I have ~30-40 of them now, scattered in different project folders. If 2to3 is not the correct solution, should I do something else?

1
  • 3
    You are correct that there's no automated tool that works on the HTML notebooks yet. This is discussed in the issue tracker here: github.com/swcarpentry/bc/issues/107 The .ipynb files are text files that you could parse with a script that takes care of this 2to3 conversion, though it may not necessarily be trivial. The thread indicates that the issue will be revisited in 2014. Commented Dec 18, 2013 at 7:04

1 Answer 1

2

You can use this script 2to3_nb.py. Just run it like this: python 2to3_nb.py <path_to_folder_containing_notebooks>.

Sign up to request clarification or add additional context in comments.

1 Comment

Suppose I have a full project that has notebooks coded in Python 2.7. I want to convert all of them to Python 3. If I run: python 2to3_nb.py <my_project_folder>, will it convert and replace all the notebooks in <my_project_folder> with Python 3 code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.