使用括号把该字符串括起来即可
例如下面一段代码,img和caption都是字符串
with open(csvpath,'w',newline='') as file:
writer=csv.writer(file)
header=['name','caption']
writer.writerow(header)
for img in os.listdir(trainpath):
imgpath=os.path.join(trainpath,img)
caption = image_caption_model.image_caption(imgpath)
data=[img,caption]
writer.writerow(data)
这些写的结果是每个字母占一个格子
应该给img和caption都加上括号
with open(csvpath,'w',newline='') as file:
writer=csv.writer(file)
header=['name','caption']
writer.writerow(header)
for img in os.listdir(trainpath):
imgpath=os.path.join(trainpath,img)
caption = image_caption_model.image_caption(imgpath)
data=[(img),(caption)]
print('data',data)
writer.writerow(data)
就可以正确的保存了