Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I disable the IPython notebook to save the results into the ipynb file?

I use the Jupyter 4.1.

I've found the results of the cells are also saved into the ipynb file. Can I disable it? I want manage it with Git.

For example, there is a cell of my notebook,

  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "autoscroll": "json-false",
    "collapsed": false,
    "ein.tags": [
     "worksheet-0"
    ],
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016-08-04 : 749591\n",
      "2016-08-05 : 447416\n",
      "2016-08-06 : 305969\n",
     ]
    }
   ],
   "source": [
    "curidx = (data.cur_day - data.start_day).days\n",
    "for iday in range(curidx, data.nday):\n",
    "     day = data.cur_day + dt.timedelta(iday - curidx)\n",
    "     print \"%s : %d\"%(day, int(pdata.barCn[iday]))\n"
    ]
   }

I don't want the contents of the outputs to be saved.

like image 952
Yantao Xie Avatar asked Aug 10 '16 09:08

Yantao Xie


People also ask

How do you hide the output of a Jupyter notebook?

There are two ways to hide content: To hide Markdown, use the {toggle} directive. To hide or remove code cells or their outputs, use notebook cell tags.

How do I suppress output in a python notebook?

Suppress functions print output If you want to stop the messages from print function with Jupyter Notebook you can use: %%capture.

How do I turn off Ipython?

Entering (and exiting) ipython You can also hit Ctrl-D to exit out of ipython. In fact, using your keyboard is the most highly recommended way.

How do I save a file from Jupyter notebook to Ipynb?

Saving your edits is simple. There is a disk icon in the upper left of the Jupyter tool bar. Click the save icon and your notebook edits are saved.


1 Answers

Thanks @Thomas K, guided by his advice, I've found the solution that is use the nbstripout. The usage is below

  1. Install the nbstripout by pip.
  2. cd to the dir of the notebook. If there is not a git repository, please init one.
  3. Run nbstripout --install to install a git attribute filter which will strip out the outputs from the ipynb file when it's added to the git cache.
like image 60
Yantao Xie Avatar answered Nov 01 '22 05:11

Yantao Xie