PY-25639 "Convert to Jupyter Notebook" removed all line breaks in code.

This commit is contained in:
Ekaterina Tuzova
2017-10-16 13:59:52 +03:00
parent 871885e2a3
commit 9f65d4e813
+6 -6
View File
@@ -1,8 +1,7 @@
import sys
import nbformat
from nbformat.v4 import new_code_cell, new_notebook
import codecs
import nbformat
import sys
from nbformat.v4 import new_code_cell, new_notebook
name = sys.argv[-1][:-3]
source = name + ".py"
@@ -13,8 +12,8 @@ def parse_python(file):
with open(file, "r") as file_descriptor:
lines = []
for line in file_descriptor:
line = line.strip()
if line.startswith('# In[') and line.endswith(']:') and lines:
line_stripped = line.strip()
if line_stripped.startswith('# In[') and line_stripped.endswith(']:') and lines:
yield "".join(lines)
lines = []
continue
@@ -22,6 +21,7 @@ def parse_python(file):
if lines:
yield "".join(lines)
cells = []
for cell_content in parse_python(source):
cells.append(new_code_cell(source=cell_content))