python - Jupyter 单行 bash 到 python 变量

标签 python jupyter jupyter-lab

我真的很喜欢 jupyter 像这样内联混合 bash 命令的能力:

for d in list_of_dirs:
    ! ls {d}

但是,有什么方法可以将这些内联命令之一的输出分配给 python 变量?例如作为 python 列表?

最佳答案

是这样的吗?

代码:

python_list = []
for d in list_of_dirs:
    temp_list = !ls {d}
    python_list.extend(temp_list)

关于python - Jupyter 单行 bash 到 python 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55599510/

相关文章:

python - 向自定义 resnet 18 架构添加简单的注意力层会导致前向传递错误

python - Jupyter 实验室无法安装任何扩展 : Assertion `data' failed

apache-spark - 在 Pyspark/Jupyter 中设置 spark.local.dir

pycharm - PyCharm Jupyter 中的环境变量

python - 我可以在 gpu 上运行 Keras 模型吗?

python - 在 JupyterLab 中以编程方式运行单元

python - Jupyter Lab 中未显示 Plotly 图表

Python:从调用函数中获取值

python - 将 gspread 与代理一起使用

python - 删除分配给字典中每个键的值列表中的重复项的函数?