相关疑难解决方法(0)

将IPython变量作为参数传递给bash命令

如何从Ipython/Jupyter笔记本执行bash命令,将python变量的值作为参数传递,如下例所示:

py_var="foo"
!grep py_var bar.txt
Run Code Online (Sandbox Code Playgroud)

(显然我想要grep foo而不是文字字符串py_var)

python ipython command-line-arguments jupyter-notebook

27
推荐指数
2
解决办法
1万
查看次数

如何在Google Colab终端命令中使用Python变量?

我有一个具有以下内容的单元:

import os
os.mkdir('123')
name = '123'
!rm -r name
Run Code Online (Sandbox Code Playgroud)

我想将变量的值传递到最后一行。我怎样才能做到这一点?

python ubuntu google-colaboratory

4
推荐指数
2
解决办法
1355
查看次数

将 Ipython 变量作为字符串参数传递给 shell 命令

如何从 Ipython/Jupyter notebook 执行 shell 命令,将 python 字符串变量的值作为 bash 参数中的字符串传递,如下例所示:

sp_name = 'littleGuy' #the variable

sp_details = !az ad app list --filter "DisplayName eq '$sp_name'" #the shell command
Run Code Online (Sandbox Code Playgroud)

我试过$sp_name单独使用${sp_name}{sp_name}等等,如this related question中所述,但都没有奏效。

这里的关键是变量名需要在 shell 命令中作为字符串引用。

编辑1:

@manu190466。我从字符串输出判断您的解决方案有效。出于某种原因,它在实践中似乎没有。我想知道az ad app listURL 是对查询进行编码还是什么......?

想法?

在此处输入图片说明

python shell ipython

4
推荐指数
1
解决办法
1896
查看次数