Created
October 8, 2013 17:54
-
-
Save paulgb/6888709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import getsize | |
from progressbar import ProgressBar | |
class ProgOpen(object): | |
def __init__(self, filename): | |
self.filename = filename | |
def __iter__(self): | |
return self | |
def __enter__(self, *params): | |
size = getsize(self.filename) | |
self.fh = open(self.filename) | |
self.progbar = ProgressBar(maxval=size).start() | |
return self | |
def __exit__(self, *params): | |
self.fh.close() | |
def next(self): | |
self.progbar.update(self.fh.tell()) | |
rn = self.fh.next() | |
return rn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment