2014-04-18 21 views
1

我正在尋找一個實例的示例,其中我們導入Python getpass庫,輸入密碼,並且密碼不會回顯到終端。python getpass示例,其中密碼未回顯到終端

這裏是它呼應了密碼到終端的例子:

$ python 
>>> import getpass 
>>> getpass.GetPassWarning 
<class 'getpass.GetPassWarning'> 
>>> getpass.getpass(stream=None) 
Password: 
'hello' 
>>> 

有人可以給一個例子,其中不回顯到終端?

謝謝!

+5

你必須分配的值:'my_pwd = getpass.getpass(流=無)' – fredtantini

+0

謝謝!奇蹟般有效! – SeanPlusPlus

回答

5

您應該將密碼寫入或保存到變量中。那麼密碼將不會被回顯。 例如:

import getpass                  

p=getpass.getpass("Enter the Password:") 

Enter the Password: 

print (p) 

Output on console: 通@ 123