Far*_*ian 5 python cloud-storage google-cloud-storage
我想使用Google云端存储客户端库函数.
为此,我必须这样做import cloudstorage.为了让cloudstorage我下载Google云端存储客户端库.
我尝试导入cloudstorage使用python -c "import cloudstorage".我收到以下错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/fghavamian/Documents/PhD_work/Codes/python/convnet_gcloud/cloudstorage/__init__.py", line 20, in <module>
from .api_utils import RetryParams
File "/Users/fghavamian/Documents/PhD_work/Codes/python/convnet_gcloud/cloudstorage/api_utils.py", line 173
except self.retriable_exceptions, e:
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
正如其中一条评论所说,这是使用 Python 3 的问题,其中语法已更改。看来您使用的 Google Cloud Storage 库没有得到很好的支持,更推荐的库是google-cloud-python。
假设您已经安装了Google Cloud SDK,您可以使用以下命令安装它:
pip install google-cloud-storage
Run Code Online (Sandbox Code Playgroud)
这是一些示例代码(来自文档),展示了如何读取和写入存储桶。
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1619 次 |
| 最近记录: |