I wrote this code that should give me the percentage of how many bytes I already read from a file a give in input thanks to AppJar. However, when I try to set the value of the bar it goes from 0 to 190% that obviusly is not what I want. Can someone tell me where the error is?
def apriCsv():
path = app.openBox(title="Apri File", dirName=None, fileTypes=[("File CSV", "*.csv")], asFile=False, parent=None, multiple=False, mode='r')
size = os.path.getsize(path)
percentuale = 100.0/size
letto = 0
line = ""
with open(path) as file:
reader = csv.reader(file, delimiter=',')
for riga in reader:
for i in riga: #create a string made out of all the element in riga
line += i
letto += len(line.encode('utf-8')) #get the size in bytes of the string
app.setMeter("progress", percentuale * letto, percentuale*letto ) #set the value of the bar
if riga != ["TITOLO","DESCRIZIONE","PREZZO"]:
elencoLibri.append(Libro(riga[0], riga[1], riga[2]))
app.addTableRow("elencoLibri", riga)