且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iPython中将变量作为命令行参数传递?

更新时间:2023-09-23 12:13:28

shell模式从字面上解释所有内容(否则 cmd.py 也会被评估)。我会这么做:

the shell mode interprets everything literally (else cmd.py would be evaluated as well). I would just do:

for i in range(5):
   %run cmd.py $i

来自 http://ipython.readthedocs.io/en/stable/interactive/reference.html


IPython还允许您在进行系统调用时扩展python变量的值。在{braces}中包装变量或表达式:

IPython also allows you to expand the value of python variables when making system calls. Wrap variables or expressions in {braces}:

对于简单的情况,您也可以将$添加到变量名称

For simple cases, you can alternatively prepend $ to a variable name