[英]How do I assign the output of a command to a variable in Jupyter notebook?
Is there a way to assign a value to a variable, that value which we get in terminal by writing any command?有没有办法给一个变量赋值,这个值是我们通过编写任何命令在终端中得到的?
I try with this code:我尝试使用此代码:
!number_of_lines=$(wc -l < cord_19.json)
!echo $number_of_lines
I get empty output.我得到空输出。 When I run
当我跑
!wc -l < cord_19.json
I get correct response with number.我得到了正确的数字响应。
Do you have idea what is wrong or how can I set variable?你知道出了什么问题或者我如何设置变量?
Try:尝试:
number_of_lines = !wc -l < cord_19.json
!echo $number_of_lines
or:或者:
number_of_lines = !wc -l < cord_19.json
print(number_of_lines)
See Pipe Ipython magic output to a variable?请参阅管道 Ipython 魔术输出到变量? for related discussion.
进行相关讨论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.