Passing command line arguments to argv in jupyter/ipython notebook

前端 未结 8 1283
-上瘾入骨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

    I assume that you just want to parse some arguments to the notebooks, but it's not necessary to use the command line.

    If you want to parse commands like.

    python script.py --a A --b B
    

    You can use the following code in the notebook:

    cmd = '--a A --b B'
    args = args = parser.parse_args(cmd)
    

    For parse_args, you can find more information here.

提交回复
热议问题