sys.argv 不能在 coomanline 参数中工作

sys.argv ot working in coomanline argument

我有一个简单的 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"

并继续脚本中的后续步骤。

解决了 ln = 'aws s3 ls --profile ' + str(sys.argv[1]) + ''