【发布时间】:2020-06-06 01:53:17
【问题描述】:
我有一个简单的 python 脚本,我试图在其中传递参数。
#!/usr/bin/python
import subprocess, sys
cmd = "aws s3 ls --profile sys.argv[0]"
n = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
a,b = n.communicate()
print(a)
我用下面的方法试过了,但效果不好。
cmd = "aws s3 ls --profile ' + str(sys.argv) + '"
所以当我点击
./myscript.py noc
应该是这样的
ln = "aws s3 ls --profile noc"
然后继续脚本中的后续步骤。
【问题讨论】:
-
您的代码中实际上没有调用
sys.argv。你正在寻找这样的东西吗?f"aws s3 ls --profile {sys.argv[1]}"
标签: python command-line-arguments