In Ipython, how can I pass arguments to a cell as though it were its own script?

◇◆丶佛笑我妖孽 提交于 2019-12-04 01:36:22

问题


For instance, say I have some snippet of self-contained code in a cell,

In [1]
from sys import argv
print(argv[1])

I want to be able to pass a value to the code in that cell, presumably through magic, so that

In [2]
%expelliarmus "In [1]" 69105

outputs

69105

Is there any simple way for me to do this, ideally without having to write the cell to my disk as a script?

Edit: I can't just wrap it in a function because in the notebook I'm working in (not the example I posted above) I'm trying to test stuff out with the argparse module.

来源:https://stackoverflow.com/questions/38755864/in-ipython-how-can-i-pass-arguments-to-a-cell-as-though-it-were-its-own-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!