我需要将几个目录中的图像移动到一个,并在移动之前和之后捕获这些文件的元数据。创建后使用python class.instance
在每个目录:
阅读来自indexfile.csv JPG图像,包括每个图像
上传对应的图像文件,以谷歌驱动器上的元数据的索引,与元数据
添加条目到uberindex.csv,其中包括indexfile.csv的元数据和上传后的谷歌驱动器的文件url
我的计划是为indexfile.csv的每一行创建一个类ybpic() - def下面的类的实例,并使用该实例来标识要移动的实际文件(它是索引文件中的参考),保存来自indexfile.csv的元数据,然后在最终将所有实例写出到uberindex.csv之前使用谷歌驱动器上载(其他元数据)的结果更新ybpic.instance。
我知道当答案出现时我会踢自己(真正的noob)。
我可以csv.reader indexfile.csv到一个ybpic.instance,但我不能引用每个实例分别以后使用或更新实例。 我可以将indexfile.csv中的行附加到indexlist [],并且我可以将更新后的列表返回给调用者,但我不知道更新该列表行的好方法,对于相应的图像文件,稍后使用新的元数据。
这里的ybpic高清
class ybpic():
def __init__(self,FileID, PHOTO, Source, Vintage, Students,Folder,Log):
self.GOBJ=" "
self.PicID=" "
self.FileID=FileID
self.PHOTO=PHOTO
self.Source=Source
self.Students=Students
self.Vintage=Vintage
self.MultipleStudents=" "
self.CurrentTeacher=" "
self.Folder=Folder ## This may be either the local folder or the drive folder attr
self.Room=" "
self.Log=Log ## The source csvfile from which the FileID came
这里是填充实例和列表功能。 indexfile.csv作为photolog传递,而cwd只是工作目录:
def ReadIndex(photolog, cwd, indexlist) :
""" Read the CSV log file into an instance of YBPic. """
with open(photolog,'r') as indexin :
readout = csv.reader(indexin)
for row in readout:
indexrow=ybpic(row[0],row[1],row[2],row[3],row[4],cwd,photolog)
indexlist.append(row) ### THIS WORKS TO APPEND TO THE LIST
### THAT WAS PASSED TO ReadIndex
return(indexlist)
任何和所有的帮助,非常感谢。
不直接相关,但请查看'glob',特别是'glob.glob'(用于使用通配符获取文件列表)和'shutil'用于复制文件。两者都是内置库的一部分。 – Benjamin