ct_*_*hon 1 python-2.7 google-cloud-platform tensorflow
I\xe2\x80\x99m 通过 Google 云学习/Tensorflow 快速入门示例进行工作,如下所示: https: //cloud.google.com/ml/docs/quickstarts/training
\n\n我希望我的 python 程序能够访问我存储在 Google Cloud 存储桶(例如 gs://mybucket)中的数据。如何在 python 程序中执行此操作而不是从命令行调用它?
\n\n具体来说,云学习的快速入门示例利用了他们提供的数据,但如果我想提供自己存储在存储桶(例如 gs://mybucket)中的数据怎么办?
\n\n我在这里注意到类似的帖子:How can I get the Cloud ML service account byprogrammatically in Python? ...但我可以\xe2\x80\x99t似乎安装了googleapiclient模块。
\n\n有些帖子似乎提到了 Apache Beam,尽管我无法判断该 xe2x80x99 是否与我相关,但除此之外我无法弄清楚如何下载或安装它,无论它是什么。
\n如果我正确理解你的问题,你想以编程方式与 Python 中的 GCS 对话。
官方文档是一个很好的起点。
首先,使用 pip 获取模块:
pip install --upgrade google-cloud-storage
Run Code Online (Sandbox Code Playgroud)
然后:
from google.cloud import storage
client = storage.Client()
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())
blob.upload_from_string('New contents!')
blob2 = bucket.blob('remote/path/storage.txt')
blob2.upload_from_filename(filename='/local/path.txt')
Run Code Online (Sandbox Code Playgroud)