[英]Upload Python List to Google Cloud Storage and Overwrite File
I have a JSON file customer_records.json
in a Google Cloud Storage bucket called sales_data
.我在名为
sales_data
的 Google Cloud Storage 存储桶中有一个 JSON 文件customer_records.json
。
In a Python file, I have the following list:在 Python 文件中,我有以下列表:
metrics_map = [{"State": "Austin", "City": "Texas"}, {"State": "New York", "City": "New York"}]
How can I upload this list into a Google Cloud Storage bucket and overwrite the customer_records.json
file?如何将此列表上传到 Google Cloud Storage 存储桶并覆盖
customer_records.json
文件?
I tried to use blob.upload_from_file(metrics_map)
, but this command does not take a list object.我尝试使用
blob.upload_from_file(metrics_map)
,但此命令不使用列表 object。
You can use blob.upload_from_string
to upload serialized JSON.您可以使用
blob.upload_from_string
上传序列化的 JSON。 See the Python Docs or Uploading Objects Docs and search for upload_from_string
.请参阅Python 文档或上传对象文档并搜索
upload_from_string
。 You can use json.dumps(metrics_map)
to create a string from your JSON.您可以使用
json.dumps(metrics_map)
从您的 JSON 创建一个字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.