[英]Python: executing a terminal command from jupyter notebook
I want to run C++ simulations from a jupyter notebook. 我想从jupyter笔记本运行C ++模拟。 The program needs three values in input, ie 10
, 0.2
and 0.6
. 程序需要三个值中输入,即10
, 0.2
和0.6
。
This what I am doing now and it works fine: 这是我现在正在做的,并且工作正常:
## Compile
! mpicxx -o main main.cpp Node.cpp Agent.cpp -std=gnu++11
## Run
! mpirun -np 1 ./main 10 0.2 0.6
But if try to declare those values before, it does not recognizes them. 但是,如果尝试在之前声明这些值,它将无法识别它们。
a = 10
b = 0.2
c = 0.6
! mpirun -np 1 ./main a b c
you need to type it like this 您需要这样输入
a = 10
b = 0.2
c = 0.6
! mpirun -np 1 ./main {a} {b} {c}
It looks like (from this document ) you can wrap your Python variables in curly braces or else prefix them with the $
to get the to expand for the shell. 看起来(从本文档开始 )您可以将Python变量括在花括号中,也可以在它们之前加上$
前缀,以扩展到shell中。 Eg, ! mpirun -np 1 ./main {a} {b} {c}
例如! mpirun -np 1 ./main {a} {b} {c}
! mpirun -np 1 ./main {a} {b} {c}
! mpirun -np 1 ./main {a} {b} {c}
! mpirun -np 1 ./main $a $b $c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.