pyqt4 - python matching files from one list with files from another list based on name -
i learning python , programing in general , need assistance.
i wrote python script reads 1 file, unique values, opens second file , and uses unique values makes calculation(script long upload) created gui using pyqt4 allowed user browse clicking qpushbutton
, stored file path in qlineedit
set file in script f1 = self.lineedit.text()
, f2 = self.lineedit2.text
worked however, need allow user select multiple files , match every file 1 corresponding file 2 since dependent on each other
here updates made widget functions accept multiple files:
def first_file_set(self): dlg = qfiledialog() files = dlg.getopenfilenames() self.listwidget.additems(list(files)) def second_file_set(self): dlg = qfiledialog() filenames = dlg.getopenfilenames() self.listwidget_2.additems(list(filenames)) def clearf(self): item in self.listwidget2.selecteditems(): self.listwidget.clear() def clears(self): item in self.listwidget.selecteditems(): self.listwidget_2.clear() def calculate(self): #code long how reading files l1 = [] f1 = self.listwidget.item() open(f1,'r') csvfile: csvreader = csv.reader(csvfile) line in csvreader: l1.append(list(line)) # more code l2 = [] f2 = self.listwidget_2.item()[0] open(f2,'r') csvfile: csvreader = csv.reader(csvfile) line in csvreader: l2.append(list(line)) # more code
i still want use code wrote on multiple files time.
eg.
open 1 file file path in listwidget
, grab unique items, find file same name path in listwidget_2
use unique items perform calculations, repeat every file in list
if file 1 , 2 have same string in name how pull , match them?
example file 1 names: filemap02.csv filemap03.csv filemap04.csv
example file 2 names: newmap02.csv newmap03.csv newmap04.csv
so couldn't test since did not post working example, should it:
for item in self.listwidget.selecteditems(): #first file fn1=str(item.text()) #get string needs match matchstr=fn1.replace("file","") #find matching item in second listwidget fn2=self.listwidget2.finditems(matchstr,qtcore.qt.matchexactly) # calculations whateverfunc(fn1,fn2)
hope helps.
Comments
Post a Comment