I am wondering if it is possible to create a notebook that is able to run code in both python2 and python3.
So far, I have a notebook in python2, but as I run python3 code in a cell, it is unable to run python2 code in other cells.
Use the %%python2 cell magic at the top of the cell to make the rest of the cell run in python2. Same with %%python3 for python3. You should only really need to use one though, as the one which is the native kernel shouldn't need to have it's magic declared.
In a python2 notebook:
Cell1:
%%python3
print("Hello world!")
Cell2:
print "Hello world!"
from __future__ import print_function. Following cells in python2 that use print "something" instead of print("something") return an error.from __future__ import print_function in one cell without affecting the computation in other cells?