Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to deal with ipython magic commands #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ipython_notebook_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def write_notebook_data_to_py(notebook_data, out_file_path):
output.write('\n')
for item in cell['source']:
if cell['cell_type']=='code':
output.write(item)
# Comment out ipython magic commands like "%matplotlib inline"
if item[0] == '%':
output.write('# ')
output.write(item)
else:
output.write(item)
else:
output.write('# ')
output.write(item)
Expand Down
7 changes: 6 additions & 1 deletion notebook_v4_to_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ def write_notebook_data_to_py(notebook_data, out_file_path):
output.write('\n')
for item in cell['source']:
if cell['cell_type']=='code':
output.write(item)
# Comment out ipython magic commands like "%matplotlib inline"
if item[0] == '%':
output.write('# ')
output.write(item)
else:
output.write(item)
else:
output.write('# ')
output.write(item)
Expand Down
6 changes: 5 additions & 1 deletion py_to_notebook_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def open_cell(line, execution_count):
else:
source.append(line)
elif current_cell=='code':
source.append(line)
# Remove comments for ipython magic commands like "%matplotlib inline"
if line[0:3] == '# %':
source.append(line[2:])
else:
source.append(line)

last_cell = True
outputcells = close_cell(current_cell)
Expand Down