2020def convert_py_code_to_notebook (text : str ) -> nbformat .notebooknode .NotebookNode :
2121 """
2222 Convert python text to a notebook.
23- "''' begin text" ends any open blocks, and starts a new markdown block
24- "''' # end text" ends text, and starts a new code block
25- "'''end code'''" ends code blocks, and starts a new code block
23+ "''' begin text" ends any open blocks, and starts a new markdown block (triple double quotes also allowed)
24+ "''' # end text" ends text, and starts a new code block (triple double quotes also allowed)
25+ "'''end code'''" ends code blocks, and starts a new code block (triple double quotes also allowed)
2626
2727 :param text: Python text to convert.
2828 :return: a notebook
@@ -99,9 +99,9 @@ def prepend_code_cell_to_notebook(
9999def convert_py_file_to_notebook (* , py_file : str , ipynb_file : str ) -> None :
100100 """
101101 Convert python text to a notebook.
102- "''' begin text" ends any open blocks, and starts a new markdown block
103- "''' # end text" ends text, and starts a new code block
104- "'''end code'''" ends code blocks, and starts a new code block
102+ "''' begin text" ends any open blocks, and starts a new markdown block (triple double quotes also allowed)
103+ "''' # end text" ends text, and starts a new code block (triple double quotes also allowed)
104+ "'''end code'''" ends code blocks, and starts a new code block (triple double quotes also allowed)
105105
106106 :param py_file: Path to python source file.
107107 :param ipynb_file: Path to notebook result file.
@@ -120,9 +120,9 @@ def convert_py_file_to_notebook(*, py_file: str, ipynb_file: str) -> None:
120120def convert_notebook_code_to_py (nb : nbformat .notebooknode .NotebookNode ) -> str :
121121 """
122122 Convert ipython notebook inputs to a py code.
123- "''' begin text" ends any open blocks, and starts a new markdown block
124- "''' # end text" ends text, and starts a new code block
125- "'''end code'''" ends code blocks, and starts a new code block
123+ "''' begin text" ends any open blocks, and starts a new markdown block (triple double quotes also allowed)
124+ "''' # end text" ends text, and starts a new code block (triple double quotes also allowed)
125+ "'''end code'''" ends code blocks, and starts a new code block (triple double quotes also allowed)
126126
127127 :param nb: notebook
128128 :return: Python source code
@@ -133,13 +133,13 @@ def convert_notebook_code_to_py(nb: nbformat.notebooknode.NotebookNode) -> str:
133133 if len (cell .source .strip ()) > 0 :
134134 if cell .cell_type == 'code' :
135135 if code_needs_end :
136- res .append (" \n ''' end code''' \n " )
136+ res .append (' \n """ end code""" \n ' )
137137 res .append (cell .source .strip ('\n ' ))
138138 code_needs_end = True
139139 else :
140- res .append (" \n ''' begin text" )
140+ res .append (' \n """ begin text' )
141141 res .append (cell .source .strip ('\n ' ))
142- res .append ("''' # end text\n " )
142+ res .append ('""" # end text\n ' )
143143 code_needs_end = False
144144 res_text = '\n ' + ('\n ' .join (res )).strip ('\n ' ) + '\n \n '
145145 return res_text
@@ -148,9 +148,9 @@ def convert_notebook_code_to_py(nb: nbformat.notebooknode.NotebookNode) -> str:
148148def convert_notebook_file_to_py (* , ipynb_file : str , py_file : str ) -> None :
149149 """
150150 Convert ipython notebook inputs to a py file.
151- "''' begin text" ends any open blocks, and starts a new markdown block
152- "''' # end text" ends text, and starts a new code block
153- "'''end code'''" ends code blocks, and starts a new code block
151+ "''' begin text" ends any open blocks, and starts a new markdown block (triple double quotes also allowed)
152+ "''' # end text" ends text, and starts a new code block (triple double quotes also allowed)
153+ "'''end code'''" ends code blocks, and starts a new code block (triple double quotes also allowed)
154154
155155 :param ipynb_file: Path to notebook input file.
156156 :param py_file: Path to python result file.
0 commit comments