我需要將幾個目錄中的圖像移動到一個,並在移動之前和之後捕獲這些文件的元數據。創建後使用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