I am trying to create a utility program, but after the password is correctly typed in it goes to the main screen, and shows the password right above it! Is there any way I can automatically make the program clear the shell before it goes to the main menu?
Asked
Active
Viewed 190 times
0
-
2The proper way to input a password is with `stty -echo`. Then clearing the screen will not be necessary. – tripleee May 04 '13 at 08:10
1 Answers
0
You can use subprocess
module to execute the "clear"
(linux/mac) or "cls"
(windows) command based on your OS.
>>> import subprocess,sys
>>> if sys.platform in ("linux2", "linux", "darwin"): #for linux / mac
... subprocess.call("clear")
... elif sys.platform.statswith("win"): #for windows
... subprocess.call("cls")
List of possible sys.platform
values:
System platform value
Linux (2.x and 3.x) 'linux2'
Linux (py 3.3) 'linux'
Windows 'win32'
Windows/Cygwin 'cygwin'
Mac OS X 'darwin'
OS/2 'os2'
OS/2 EMX 'os2emx'
RiscOS 'riscos'
AtheOS 'atheos'

Ashwini Chaudhary
- 244,495
- 58
- 464
- 504
-
Might I recommend using a `try: except:` block to attempt the linux/mac method, and then use the windows method on exception? It should raise an `OSError` specifically. This might make it more portable. – SethMMorton May 04 '13 at 06:52
-
-
-
@Ashwini Chaudhary Sure. Let me rephrase my comment. Might I recommend using `sys.platform` to check the platform and use the proper method? This might make it more portable. – SethMMorton May 04 '13 at 06:58