Advertisement
AceScottie

overwright lines

Jul 21st, 2018
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import sys
  2.  
  3. textlen = 0 #used to clear lines this is required or with input of "hello" and "test" it will show "testo"
  4. def writeline(text):
  5.     global textlen
  6.     if text== "" or not isinstance(text, basestring):
  7.         raise "Requred string is not set" ##basic error handeling (this may be incorrect, im using classes where i got this code from
  8.     sys.stdout.write('\r' + ' ' * textlen + '\r') ##pints spaces equle to the amount of characters from the last message and overwrights the last message
  9.     sys.stdout.flush()
  10.     sys.stdout.write('\r' + str(text) + '\r') ##overwrights those spaces with new characters
  11.     sys.stdout.flush()
  12.     textlen = len(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement