【问题标题】:Python: executing a terminal command from jupyter notebookPython:从 jupyter notebook 执行终端命令
【发布时间】:2019-08-20 08:34:27
【问题描述】:

我想从 jupyter notebook 运行 C++ 模拟。该程序需要输入三个值,即100.20.6

这是我现在正在做的,它工作正常:

## Compile
! mpicxx -o main main.cpp Node.cpp Agent.cpp -std=gnu++11
## Run
! mpirun -np 1 ./main 10 0.2 0.6

但是如果之前尝试声明这些值,它就无法识别它们。

a = 10
b = 0.2
c = 0.6
! mpirun -np 1 ./main a b c

【问题讨论】:

标签: python jupyter-notebook


【解决方案1】:

你需要这样输入

a = 10
b = 0.2
c = 0.6
! mpirun -np 1 ./main {a} {b} {c}

【讨论】:

    【解决方案2】:

    看起来(来自this document)您可以将 Python 变量包装在花括号中,或者在它们前面加上 $ 以扩展 shell。例如,! mpirun -np 1 ./main {a} {b} {c}

    【讨论】:

      【解决方案3】:
      ! mpirun -np 1 ./main {a} {b} {c}
      

      ! mpirun -np 1 ./main $a $b $c
      

      【讨论】:

        猜你喜欢
        • 2016-12-06
        • 2022-11-12
        • 1970-01-01
        • 2019-07-13
        • 1970-01-01
        • 1970-01-01
        • 2018-06-01
        • 2021-11-25
        相关资源
        最近更新 更多