0

I am doing jupyter-nbconvert --to script mynb.ipynb to get a .py from my notebook. This gives me everything in the notebook. I was wondering if I can set nbconvert to save in the .py script only the cells marked as initialization in my notebook. I presume I need to make a template for that, but customizing if nbconvert reads not very well to me, especially for this case.

This is how the ipynb looks like. Can one use "init_cell": true in the customization?

 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-06T02:39:41.586987Z",
     "start_time": "2018-07-06T02:39:41.412779Z"
    },
    "collapsed": true,
    "tags": [
     "ATaggedCell"
    ]
   },
   "outputs": [],
   "source": [
    "# this is tagged, but is not an initialization cell\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "init_cell": true
   },
   "outputs": [],
   "source": [
    "# this is not tagged, but is an initialization cell\n",
    "import pandas as pd"
   ]
  }
 ],
Rho Phi
  • 1,182
  • 1
  • 12
  • 21
  • How is the cell is marked? Is it by a tag or by some metadata item? If you read this section, it might give you some inspiration: https://nbconvert.readthedocs.io/en/latest/customizing.html#Templates-using-cell-tags – Yu Shen Jun 27 '18 at 19:38
  • Thanks for picking my question! As far as I know `tags` are not the same as `initialization`. Would be nice if one can use the flag for initialization in the .tpl – Rho Phi Jun 30 '18 at 10:55
  • 1
    Can you provide an example notebook so that we can try to figure out? – Yu Shen Jun 30 '18 at 15:24
  • yes, but how? sorry, I do not see an "attach" feature on this post ... – Rho Phi Jul 06 '18 at 03:41

0 Answers0