Passing command line arguments to argv in jupyter/ipython notebook

前端 未结 8 1308
-上瘾入骨i
-上瘾入骨i 2020-11-28 09:34

I\'m wondering if it\'s possible to populate sys.argv (or some other structure) with command line arguments in a jupyter/ipython notebook, similar to how it\'s

8条回答
  •  星月不相逢
    2020-11-28 10:18

    If the goal is to run a notebook with configurable arguments passed from commandline, I think the easiest way is to use environment variables, like this:

    NB_ARGS=some_args jupyter nbconvert --execute --to html --template full some_notebook.ipynb
    

    Then in the notebook, you can import os and use os.environ['NB_ARGS']. The variable value can be some text that contains key-value pairs or json for example.

提交回复
热议问题