【发布时间】:2019-11-16 23:16:40
【问题描述】:
我在创建 Python 脚本时遇到了一些问题,希望您能帮助我。
脚本应该从多个图像中读取 exif 信息(日期、时间和 GPSInfo),并将按日期排序的结果写入 CSV 文件。
目前我设法将数据写入 CSV 文件。但我无法按日期对条目进行排序。
# for every file in the directory get the latlng
for file in os.listdir("/path/"):
if file.endswith(".jpg" or ".png"):
path_name = '/path'+ file
meta_data = ImageMetaData(path_name)
latlng =meta_data.get_lat_lng()
date = meta_data.date
print(latlng, date)
with open('dez.csv', 'w', newline='') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
for x in range(0, 10):
spamwriter.writerow(latlng)
spamwriter.writerow(date)
【问题讨论】:
-
只是让你知道,你应该完成
writer.writerow([date, latlng])。您的代码现在只是编写一个字符串,其中包含两个作为单个 csv 列。 -
熊猫是你可以使用的东西吗,它非常适合这种情况
-
@oppressionslayer 你的评论对他有什么帮助?
-
您的代码错误
file.endswith(".jpg" or ".png")将首先执行".jpg" or ".png",其评估结果为True,因此您的代码执行if file.endswith(True),这将引发TypeError。您运行以获得结果的代码与您在此处粘贴的代码不同。
标签: python python-3.x csv writer