【问题标题】:sys.argv ot working in coomanline argumentsys.argv 在 cooma 行参数中不起作用
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    相关资源
    最近更新 更多