import cloudstorage, SyntaxError: invalid syntax

前端 未结 1 1634
醉话见心
醉话见心 2021-01-12 20:23

I would like to use Google Cloud Storage Client Library Functions.

For that I have to import cloudstorage. To get the cloudstorage I downl

相关标签:
1条回答
  • 2021-01-12 21:02

    As one of the comments says, this is an issue with using Python 3, where the syntax has changed. It looks like the Google Cloud Storage library you are using is not as well supported and that the more recommended library is google-cloud-python.

    You can install it with the command below, assuming you have installed the Google Cloud SDK:

    pip install google-cloud-storage
    

    Here is some sample code (from the docs) that shows how to read and write to a bucket.

    from google.cloud import storage
    client = storage.Client()
    # https://console.cloud.google.com/storage/browser/[bucket-id]/
    bucket = client.get_bucket('bucket-id-here')
    # Then do other things...
    blob = bucket.get_blob('remote/path/to/file.txt')
    print(blob.download_as_string())  # read content from bucket and print to stdout
    blob.upload_from_string('New contents!')
    blob2 = bucket.blob('remote/path/storage.txt')
    blob2.upload_from_filename(filename='/local/path.txt')  # write from path.txt to storage.txt
    
    0 讨论(0)
提交回复
热议问题