我正在尝试执行以下命令:
result = subprocess.check_output("curl -o '/Users/user/Desktop/workbook.twb' -u xxx:yyy https://bitbucket.xyz.com/rest/api/1.0/projects/xxx/repos/xxx/raw/yyy/test_folder/test.twb", shell=True)
在上述命令中,我需要将/Users/user/Desktop/workbook.twb替换为字符串变量,例如filePath和https://bitbucket.xyz.com/rest/api/1.0/projects/xxx/repos/xxx/raw/yyy/test_folder/test.twb以及另一个变量,例如repo_path ..如何实现?
我尝试了多种方法,但所有方法都出现格式错误。
答案 0 :(得分:2)
类似的东西:
param_a = "foo"
param_b = "bar"
query_url = "http://some.host/{a}/{b}.xml".format(a=param_a, b=param_b)
print(query_url) # To understand what's happening.
command = "curl -o '{output_file}' '{query_url}'".format(
output_file="/Users/me/foo-bar",
query_url=query_url
)
print(command)
result = subprocess.check_output(command, shell=True)
使每一步都小。如有疑问,请打印中间值。