Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def show_progress(file_name, chunk_size=1024):
- fh = open(file_name, "r")
- total_size = os.path.getsize(file_name)
- total_read = 0
- while True:
- chunk = fh.read(chunk_size)
- if not chunk:
- fh.close()
- break
- total_read += len(chunk)
- print "Progress: %s percent" % (total_read/total_size)
- yield chunk
- for chunk in show_progress("my_file.txt"):
- # Process the chunk
- pass
- >>> class MyFile(file):
- ... def read(self,*args,**kw):
- ... # start timing
- ... result= super(MyFile,self).read(*args,**kw)
- ... # finish timing
- ... return result
Add Comment
Please, Sign In to add comment