python move cursor to previous line 1

python move cursor to previous line

"\033[F" – move cursor to the beginning of the previous line
"\033[A" – move cursor up one line

Example:
  import sys
  sys.stdout.write("\033[F")
  sys.stdout.write("This line is replaced one")
  sys.stdout.write("\033[A")
  sys.stdout.write("More text is added to the previous line")
  sys.stdout.flush()

Here is what the above code is Doing:
1. Move the cursor to the beginning of the previous line
2. Write the text “This line is replaced one”
3. Move the cursor up one line
4. Write the text “More text is added to the previous line”
5. Flush the buffer

Similar Posts