From 9f65d4e8134497b5d1b15f27cdfc6f5a9176cf3f Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Mon, 16 Oct 2017 13:51:56 +0300 Subject: [PATCH] PY-25639 "Convert to Jupyter Notebook" removed all line breaks in code. --- python/helpers/py2ipnb_converter.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/helpers/py2ipnb_converter.py b/python/helpers/py2ipnb_converter.py index 5d538379cede..7c0aa8fab9bb 100644 --- a/python/helpers/py2ipnb_converter.py +++ b/python/helpers/py2ipnb_converter.py @@ -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))