Skip to content

Instantly share code, notes, and snippets.

@RussellLuo
Created June 16, 2014 03:48
Show Gist options
  • Select an option

  • Save RussellLuo/c5c50bd2f72ff061cfc7 to your computer and use it in GitHub Desktop.

Select an option

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.
#!/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