Keep Track Of Number Of Bytes Read
I would like to implement a command line progress bar for one of my programs IN PYTHON which reads text from a file line by line. I can implement the progress scale in one of two
Solution 1:
bytesread = 0whileTrue:
line = fh.readline()
if line == '':
break
bytesread += len(line)
Or, a little shorter:
bytesread = 0for line in fh:
bytesread += len(line)
Using os.path.getsize()
(or os.stat
) is an efficient way of determining the file size.
Post a Comment for "Keep Track Of Number Of Bytes Read"