0

I am making a program in python and want to clear what the user has enterd, this is because I am using the keyboard function to register input as is is given, but there is still text left over after a keypress is registerd and I don't want this to happen.

I was woundering if there is a module that exists to remove text that is being entered

Any help would be greatly apreciated, and just the name of a module is fine; I can figure out how to use it, just cant find an appropriate module.

EDIT: Sorry if i did not make my self clear, I dont really want to clear the whole screen, just what the user has typed. So that they don't have to manually back space after their input has been taken.

Jamie Bowen
  • 55
  • 1
  • 8
  • 1
    do you mean [clearing the console](https://stackoverflow.com/q/517970/3462319)? – depperm Jul 11 '19 at 17:16
  • Possible duplicate of [Delete Characters in Python Printed Line](https://stackoverflow.com/questions/9949887/delete-characters-in-python-printed-line) – Grzegorz Bokota Jul 11 '19 at 17:18
  • @Grzegorz Bokota , I looked at the possible duplicate and It should be the right module, Ill look into it, so for now ill mark the question as answerd. – Jamie Bowen Jul 11 '19 at 18:00

4 Answers4

2

One way to accomplish this is to use the operating system's clear function. In windows this is cls and on unix systems this is clear. To call these you would use the os module.

For example:

os.system("clear")
Calder White
  • 1,287
  • 9
  • 21
0

You can use a lambda to make it easier, e.g.:

import os
clear = lambda: os.system('clear') # or 'cls', in case you are on windows.
clear()
Dico
  • 320
  • 4
  • 7
0

You can use os.system('clear') on Mac/Linux or os.system('cls') on Windows

However on some systems you may still be able to scroll up in the terminal. In some cases you can use the up arrow key to see previously entered text.

If it is a password or other sensitive information you can use the getpass module

import getpass
password = getpass.getpass("Enter your password: ")

This will both mask the input and prevent you from up-arrowing into it

Jmonsky
  • 1,519
  • 1
  • 9
  • 16
0

'sys.stdout.write' is the moduel I was looking for.

Jamie Bowen
  • 55
  • 1
  • 8