Can I get console input without echo in python?
            Asked
            
        
        
            Active
            
        
            Viewed 3.9k times
        
    55
            
            
        - 
                    Console **input** and **echo**? Does not compute. Need more detail. – Daniel DiPaolo Jan 06 '11 at 15:56
 - 
                    @Daniel I think they're using "echo" to mean "printing program inputs", similar to CMD's `@echo on` – wjandrea May 31 '23 at 18:43
 
3 Answers
76
            Use getpass:
>>> from getpass import getpass
>>> getpass()
Password:
'secret'
        Josh Lee
        
- 171,072
 - 38
 - 269
 - 275
 
- 
                    1
 - 
                    @tm1rbrt In that case, [curses](http://docs.python.org/library/curses.html) is probably your best option. – Josh Lee Jan 06 '11 at 16:00
 - 
                    I haven't tried it, but you could also import the `readline` module. The docs of `getpass` don't mention `readline`, but `readline` changes the behavior of `raw_input()`, for instance. – Apalala Jan 06 '11 at 16:52
 
12
            
            
        There is also another solution (at least on unix systems, I don't know if this is working on Windows). Simply switch off the console output and use raw_input:
os.system("stty -echo")
password = raw_input('Enter Password:')
os.system("stty echo")
print "\n"
        Michael
        
- 129
 - 1
 - 2
 
- 
                    1Be warned that `stty -echo` will persist until `stty echo` is called. This includes persisting outside the python session, should `raw_input` cause python to exit. – Logan Byers Jun 14 '17 at 20:51
 
0
            
            
        Maybe the 'console' module is your only bet (it's kinda 'fork' of the curses module for Unix), however I haven't seen anything related to terminal echo disabling in its homepage, you might try to dig into it by yourself.
        mguillech
        
- 336
 - 1
 - 2
 
- 
                    It's not that cross-platform at this point --- it only supports Windows through Windows 2000. – JasonFruit Apr 06 '11 at 16:32