Jupyter 笔记本感叹号参数

Ali*_*ine 2 python jupyter-notebook

在 中jupyter notebook,我们可以使用感叹号执行 shell 命令,例如:

!ls *.png
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种将参数传递给该命令的方法,例如:

extention='*.png'
!ls %extention
Run Code Online (Sandbox Code Playgroud)

我知道使用os.systemsubprocess.check_output可以做到这一点,但我想使用感叹号,因为这会给我实时输出。

Ali*_*ine 10

这可以使用{},例如:

extention='*.png'
!ls {extention}
Run Code Online (Sandbox Code Playgroud)

  • 它不适用于我的情况。您能提示一下可能是什么原因吗? (3认同)