Part of my python program is to load the contents of a (csv) file into a list. Since this file is large, I'd like to add some progress data about it. This is what I'm doing right now:
def loadFile(infilepath):
answer = []
with open(infilepath) as infile:
for progress,row in enumerate(csv.reader(infile), 1):
if not progress%10000:
progress = format(progress, ',')
print(progress, '\b'*len(progress), sep='', end='', flush=True)
answer.append(doStuffWith(row))
return answer
print("Loading Data... ", end='', flush=True)
data = loadData('path/to/file')
Normally, I'd replace the print(progress, '\b'*len(progress), ...) with print(progress, '\r', ...) to bring the cursor back to the start of the line. But that's not an option here, as the start of line is offset by "Loading Data... ". I was told that I could use progressbar2 for this, but I can't seem to figure out how to make it write actual values, instead of a progress bar.
I'd appreciate any help on this