79791550

Date: 2025-10-15 19:38:39
Score: 0.5
Natty:
Report link

I was able to use the Blob.open() method to treat blobs more like typical file i/o. Documentation: https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.blob.Blob#google_cloud_storage_blob_Blob_open

from google.cloud import storage
from oauth2client.client import GoogleCredentials
import os

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "<pathtomycredentials>"

a=[1,2,3]

b=['a','b','c']

storage_client = storage.Client()
bucket = storage_client.get_bucket("<mybucketname>")

blob = bucket.blob("Hummingbirds/trainingdata.csv")

with blob.open("w") as writer:
    for eachrow in range(3):
        writer.write(str(a[eachrow]) + "," + str(b[eachrow]))

Note that in reading mode it doesn't read line by line but chunk by chunk, so you need to do slightly more work:

with blob.open("r") as reader:
    for chunk in reader:
        lines = chunk.splitlines(keepends = False)
        for line in lines:
            print(line)
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: tshynik