Python sys.argv ot在coomanline参数中工作
我有一个简单的python脚本,试图在其中传递参数Python sys.argv ot在coomanline参数中工作,python,command-line-arguments,Python,Command Line Arguments,我有一个简单的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) 我用下面的方法试过,但效果不好 c
#!/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])+'
您的代码中没有任何内容实际调用sys.argv
。你要找的是这样的东西吗<代码>f“aws s3 ls--配置文件{sys.argv[1]}”