[英]Python: executing a terminal command from jupyter notebook
我想從jupyter筆記本運行C ++模擬。 程序需要三個值中輸入,即10
, 0.2
和0.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
您需要這樣輸入
a = 10
b = 0.2
c = 0.6
! mpirun -np 1 ./main {a} {b} {c}
看起來(從本文檔開始 )您可以將Python變量括在花括號中,也可以在它們之前加上$
前綴,以擴展到shell中。 例如! 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.