import argparse
import googleapiclient.discovery
def create_service():
return googleapiclient.discovery.build('storage', 'v1')
def list_buckets(service, project_id):
buckets = service.buckets().list(project=project_id).execute()
return buckets
def main(project_id):
service = create_service()
buckets = list_buckets(service, project_id)
print(buckets)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('project_id', help='Your project iD')
args = parser.parse_args()
main(args.project_id)
#需要知道如何运行这个例子。因为我是python的新手。当我执行它时,给出了很少的参数。
答案 0 :(得分:0)
我认为您看到的错误是:
usage: your_script.py [-h] project_id
your_script.py: error: too few arguments
您需要指定项目ID。因此,如果您之前正在运行python your_script.py
,则需要改为运行python your_script.py
your-project-id
。