Python 2.7 将Python变量传递给三倍引号的curl命令

Python 2.7 将Python变量传递给三倍引号的curl命令,python-2.7,Python 2.7,我试图将SIZ(python)变量传递给curl命令,但在执行该命令时它不会解释该值。我在这里缺少的是看起来您正试图在这一行中使用%格式化程序 SIZ=100 imap_cmd=""" curl -s -X GET --insecure -u xxx https://xxxxx/_search?pretty=true -d '{ "from":0, "size":%SIZ, "query":{ "match_all": {} }, "_source":["userEmail"] }' | gr

我试图将SIZ(python)变量传递给curl命令,但在执行该命令时它不会解释该值。我在这里缺少的是

看起来您正试图在这一行中使用
%
格式化程序

SIZ=100

imap_cmd="""
curl -s -X GET --insecure -u xxx https://xxxxx/_search?pretty=true -d '{
"from":0,
"size":%SIZ,
"query":{ "match_all": {} },
"_source":["userEmail"]
}' | grep -i userEmail|awk {'print $3'} | cut -d ',' -f1
"""
def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE)
    output = (p.communicate()[0])

    return output
试一试

有关格式化字符串的详细信息

"size":%SIZ,
imap_cmd="""
curl -s -X GET --insecure -u xxx https://xxxxx/_search?pretty=true -d '{
"from":0,
"size":%d,
"query":{ "match_all": {} },
"_source":["userEmail"]
}' | grep -i userEmail|awk {'print $3'} | cut -d ',' -f1
""" % SIZ