【发布时间】:2021-04-14 16:55:30
【问题描述】:
我在层次结构中的 gcp 云存储中有文件
data/staging1
--/temp1.json
--/temp2.json
--/temp3.json
data/staging2
--/temp1.json
--/temp2.json
--/temp3.json
想要读取 staging1 中的所有文件并移动到另一个文件夹 staging2
def getFiles(self):
filename = list(self.bucketname.list_blobs(prefix=self.prefix))
target_blob = filename[0]
print(target_blob)
filename = list(self.bucketname.list_blobs(prefix=self.prefix))
for name in filename:
local_tmp_path =name.name
local_tmp_path=self.bucketname.blob(local_tmp_path)
with open(local_tmp_path, 'r') as f:
target_blob.upload_from_file(f)
print("done")
我想在循环中读取所有文件....当我尝试打开它时显示错误
with open(local_tmp_path, 'r') as f:
TypeError: expected str, bytes or os.PathLike object, not Blob
for name in filename:
local_tmp_path =name.name
local_tmp_path=self.bucketname.blob(local_tmp_path)
with open(local_tmp_path, 'r') as f:
target_blob.upload_from_file(f)
【问题讨论】:
-
是否要将文件从存储桶位置移动到另一个位置?你需要在你的代码中读取文件,还是只是为了你所做的副本?
标签: python python-3.x google-cloud-platform google-cloud-storage