Converting ipython to python without line numbers commented

时间:2017-12-18 07:24:40

标签: python ipython ipython-notebook

The command with nbconvert i.e: $ jupyter nbconvert --to script [YOUR_NOTEBOOK].ipynb converts ipython to .py file but my python file output is something like this:

# In[1]:

  import pandas as pd

# In[2]:
  data = pd.read_csv('train.csv')
  d2  = pd.read_csv('test.csv')

I don't want the In[1]or In[2] lines at all. Is there any solution for this

1 个答案:

答案 0 :(得分:0)

我找到了解决此问题的方法here。 save magic命令documentation将所需的输入行保存到文件中; -a选项用于“附加”模式,以便将行添加到文件的末尾,而不是覆盖文件。

只是类型

%save -a myipythonsession.py 1-100

1-100代表您要保存的行号(实际上不必有100行,也可以在会话中减少行数)
-a将确保保存到已经存在的文件不会被覆盖,而是将添加您保存的行。