Skip to content

Instantly share code, notes, and snippets.

@yevrah
Created September 2, 2014 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yevrah/e833e18ace23c6546ca8 to your computer and use it in GitHub Desktop.
Save yevrah/e833e18ace23c6546ca8 to your computer and use it in GitHub Desktop.
Printing on the same line
#!/usr/bin/env python
# encoding: utf-8
# This is an example of how to print a console
# message on the same line
from time import sleep
import sys
def ps(string):
sys.stdout.write(string)
sys.stdout.flush()
sleep(0.5)
sys.stdout.write("\r")
ps("1. 25% Complete")
ps("2. 50% Complete")
ps("3. 75% Complete")
ps("4. 100% Done ")
# Clear out of the line
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment