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

Notebook to script does not respect leading whitespace #2156

Open
drblarg opened this issue Jun 14, 2024 · 0 comments
Open

Notebook to script does not respect leading whitespace #2156

drblarg opened this issue Jun 14, 2024 · 0 comments

Comments

@drblarg
Copy link

drblarg commented Jun 14, 2024

I am using nbconvert as a package vs command line to convert a notebook to a script using ScriptExporter class in python:

contents, meta = nbconvert.exporters.export(
    nbconvert.exporters.ScriptExporter,
    notebook
)

When the contents of a notebook cell are all indented by the same amount, this intention is removed in the output. This whitespace should not be removed. Is there already a way to enforce this that I am missing?

A use case for keeping the white space is to enclose multiple output cells within some scope, such as an if statement. For example:

In[1]
if is_true:

In[2]
    do_stuff1()

In[3]
   do_stuff2()

This allows greater flexibility in using the notebook as a notebook (where you choose the cells to run), and the generated script as a script (e.g. AWS pipelines) without putting scoping statements in every cell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant