Home page

Deconstructing Deep Learning + ╬┤eviations

Drop me an email | RSS feed link : Click
Format : Date | Title
  TL; DR

Total posts : 78

View My GitHub Profile

Index page


I want to convert my work as a script. Selectively.




I like to do my development in jupyter notebooks. When I convert them to scripts I need to save the whole notebook as a script and then remove what I dont need. WHY -.- I want to make a script to save only the cells I finally want for my script by adding an #export to them.

What do I need?

Lets goooo

Let us first import JSON since jupyter notebooks are JSON files

using JSON

After that we allocate a dictionary and parse the notebook. Since JSONs are just pretty dictionaries, we convert the whole file into one.

dict2 = Dict()
open(ARGS[1], "r") do f
    global dict2

Now to identify the cells we need we have to add a #export to the start of the cell. Once we do that, we can go through all the cells and take the ones which have this #export in it. Then we filter this out so it does not appear in the end script. We add all this to a string.

gstr = "";

for a in dict2["cells"]
    if "#export\n" in a["source"]
        temp = a["source"]
        temp = filter!(e->e|"#export\n",temp)
        gstr*= join(temp)

Then we write the file and we are done :)

io = open(ARGS[2]*".jl", "w")
write(io, gstr)