Created
November 7, 2018 21:42
-
-
Save heffcodex/e245fb790ccfda3bd4bcb95ee292d79d 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
import sys | |
class TxtProgress: | |
_tpl = "" | |
def __init__(self, template): | |
self._tpl = template | |
def _syswrite(self, string): | |
sys.stdout.write(string) | |
sys.stdout.flush() | |
def write(self, *args): | |
self._syswrite("\r"+(self._tpl % args)) | |
def cleanup(self): | |
self._syswrite("\r\n") |
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
progress = TxtProgress("Test: %d -> %d") # define format | |
for i in range(1, 100): | |
progress.write(i, i*i) # update this string corresponding format arguments (like "Test: %d -> %d" % (i, i*i)) | |
progress.cleanup() # normal output will be broken without it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment