5

On Windows 10, I am trying to save a Jupyter notebook as a pdf, under a name that will change for every run of the notebook.

Here is what I have so far:

name1 = 'July'
name2 = 'August'
jupyter_nb_filename = '{}_vs_{}'.format(name1,name2)
!jupyter nbconvert --output-dir="C:\\mydir\\" --output=jupyter_nb_filename --to pdf --TemplateExporter.exclude_input=True mynotebook.ipynb

  • Current behaviour: Jupyter notebook is stored as "jupyter_nb_filename.pdf"
  • Desired behaviour. Jupyter notebook to be stored as "July_vs_August.pdf"

I looked in the documentation but could not figure it out.

Any help would be greatly appreciated.

Jean_N
  • 489
  • 1
  • 4
  • 19
  • 1
    As the link that @duckboycool references covers, it is the more common/better approach in Jupyter is to use curly brackets to pass Python variables in when using the exclamation point to run shell commands in a notebook, see [here](https://stackoverflow.com/a/40932507/8508004). – Wayne Aug 03 '22 at 20:47

1 Answers1

1

You have to prefix the variable name with $ for it to be interpreted as a variable in a console command. See this question.

!jupyter nbconvert --output-dir="C:\\mydir\\" --output=$jupyter_nb_filename --to pdf --TemplateExporter.exclude_input=True mynotebook.ipynb
duckboycool
  • 2,425
  • 2
  • 8
  • 23