导入cloudstorage,SyntaxError:语法无效 [英] import cloudstorage, SyntaxError: invalid syntax

查看:101
本文介绍了导入cloudstorage,SyntaxError:语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Google云存储客户端库函数.

为此,我必须import cloudstorage.要获取cloudstorage,我下载 Google云存储客户端库.

For that I have to import cloudstorage. To get the cloudstorage I download Google Cloud Storage client library.

我尝试使用python -c "import cloudstorage"导入cloudstorage. 我收到以下错误:

I try to import cloudstorage using python -c "import cloudstorage". I get the following error:

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

我错过了什么吗?

推荐答案

正如评论之一所说,这是使用Python 3的一个问题,因为它的语法已更改.似乎您所使用的Google Cloud Storage库似乎没有得到很好的支持,并且更多推荐的库是 google-cloud-python .

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.

假设您已安装 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

这篇关于导入cloudstorage,SyntaxError:语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆