Python 口令保管箱

Python編程快速上手實踐項目題目,歡迎指證與優化!
代碼:python

#! python3
# pw.py - An insecure password locker program.
PASSWORDS = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',
'blog': 'VmALvQyKAxiVH5G8v01if1MLZF3sdt',
'luggage': '12345'}
import sys
import pyperclip
if len(sys.argv) < 2:
    print('Usage: python pw.py [account] - copy account password')
    sys.exit()

account = sys.argv[1] 
#sys.argv[]是用來獲取命令行參數的,sys.argv[0]表示代碼自己文件路徑,因此參數從1開始
# first command line arg is the account name
print (account)

if account in PASSWORDS:
    pyperclip.copy(PASSWORDS[account])
    print('Password for ' + account + ' copied to clipboard.')
else:
    print('There is no account named ' + account)

#測試命令:打開CMD,輸入py.exe + 文件名(絕對路徑)+ 命令內容,
#好比:py.exe D:\python_work\口令保管箱.py email

執行結果:編程

email
Password for email copied to clipboard.
密碼已到了剪切板:F7minlBDDuvMJuxESSKHFhTxFtjVB6
相關文章
相關標籤/搜索