Created
June 16, 2014 03:48
-
-
Save RussellLuo/c5c50bd2f72ff061cfc7 to your computer and use it in GitHub Desktop.
Print messages just on one line. That is, old messages will be replaced by new ones one the same line.
This file contains hidden or 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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import sys | |
| def oneline_print(message): | |
| sys.stdout.write('\r%s' % message) | |
| sys.stdout.flush() | |
| def oneline_end(): | |
| sys.stdout.write('\n') | |
| def progress(): | |
| import time | |
| for i in range(0, 101): | |
| oneline_print('%s%%' % i) | |
| time.sleep(0.5) | |
| oneline_end() | |
| if __name__ == '__main__': | |
| progress() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment