4

I am on windows 10 and I prefer not to install a new module (standard library solutions are accepted). I want the text that the user enters to start at the end of the third line.

My code:

print(" Enter password to unlock the Safe .\n\n password : \n\n\t2 attempts remaining .")
# code to move the cursor to the end of " password : " goes here
x = input()

output:

enter image description here

wanted output:

enter image description here

Also ANSI escape sequences don't seem to work without colorama(which unfortunately is an external module).

Nick Ven
  • 91
  • 1
  • 10

2 Answers2

2

On Windows 10 you can use ANSI escape sequences as found in Console Virtual Terminal Sequences.

Before using them you need subprocess.run('', shell=True) (prior to Python 3.5, use subprocess.call). These sequences make possible what you are looking for.

Caution: Also original Microsoft, the documentation of Erase in Display and Erase in Line is partly faulty. The parameters 1 and 2 are reversed.

This should work (although, actually entering the password seems to destroy the layout):

import subprocess
subprocess.run('', shell=True)
print(' enter password : \0337', end='')
print('\n\n\t2 attempts remaining .\0338', end='')
x = input()
-1

With Python 3 use;

print("...", end="")
Yunus
  • 1
  • 1