6

Is there a convenient way to convert several .ipynb Julia files produced with Jupyter notebook to .jl working files?

It is good if the markdown written with Jupyter are kept but not mandatory for my usage.

Here is sample of what my files contain:

{
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Some useful functions required to build the model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "distance (generic function with 1 method)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Euclidean distances between point p1 and p2\n",
    "function distance(p1,p2)\n",
    "    dist=((p1[1]-p2[1])^2+(p1[2]-p2[2])^2)^(1/2)\n",
    "    return dist\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tripletas (generic function with 1 method)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],

2 Answers 2

8

There is a very convenient way: jupytext. The docs show how you can use it both inside of jupyter or jupyterlab and at the command line.

Example:

jupytext --to jl Notebook.ipynb

from a shell you could do something like:

jupytext --to jl "path/to/notebooks/*.ipynb"
Sign up to request clarification or add additional context in comments.

Comments

6

You can also use the nbexport function from NBInclude.jl in Julia, e.g.

using NBInclude
nbexport("Notebook.jl", "Notebook.ipynb")

which also converts markdown cells into formatted and line-wrapped comments in Julia.

(Note that this package also allows you to use the notebook file directly from Julia, without conversion.)

Comments

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.