Thursday 12 September 2019

How to extract the whole executable and clear scripts from jupyter

Simply I build an .ipynb like this:

test_jupyter

And now I want to extract all python code from this .ipynb file. I have tried the File->Download as->Python (.py) menu function, and I get the following result:

# coding: utf-8

# In[13]:

def a():
    la = [1, 2, 3]
    def b():
        print 'helloworld'
        print la, len(la)
    b()
a()


# In[1]:

get_ipython().magic(u'pylab inline')


# In[6]:

a = [1, 2, 3, 4, 5]


# In[8]:

import matplotlib.pyplot as plt

# In[9]:

import numpy as np


# In[11]:

data = np.random.rand(2, 25)


# ### HelloWorld
# 1. kk
# 2. bb
# * jhah

# In[13]:


get_ipython().system(u'ipython nbconvert --to script test1.ipynb')


# In[ ]:

Is there any method to get the beautiful result (without In [*] and jupyter's magic function) like this?

# coding: utf-8

def a():
    la = [1, 2, 3]
    def b():
        print 'helloworld'
        print la, len(la)
    b()
a()


a = [1, 2, 3, 4, 5]


import matplotlib.pyplot as plt


import numpy as np


data = np.random.rand(2, 25)


# ### HelloWorld
# 1. kk
# 2. bb
# * jhah



from How to extract the whole executable and clear scripts from jupyter

No comments:

Post a Comment