python变量:从for循环中的变量读取值

2024-09-26 18:04:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从txt file读取值,并将它们传递给for循环,在该循环中对每个值进行一些处理。文件内容为GCP Storage buckets,如下所示

 gs://inxxxx12/
 gs://xxxxx1231/  etc

这些值的范围从1个存储桶到100多个存储桶

{}代码如下

  import subprocess
  import json
  import shlex

  buckets = open('permissions.txt', 'r')
  for x in buckets:
    version_on = "gsutil  versioning set on x"
    version_on = shlex.split(version_on)
    project_output = subprocess.check_output(version_on)
    print project_output 

我的问题是code的下面一行

  for x in buckets:
    version_on = "gsutil  versioning set on x"

我正在努力读取for循环中variables x的值

下面是错误

['gsutil', 'versioning', 'set', 'on', 'x']
CommandException: "versioning" command does not support "file://" URLs. Did you mean to use a gs:// URL?

有什么建议吗


Tags: inimporttxtgsforoutputonversion

热门问题