"Automate the Boring Stuff Chapter 6 : Password Locker"

"Automate the Boring Stuff Chapter 6 : Password Locker"

美好的一天。我正在经历 "Automate the Boring Stuff Chapter 6 : Password Locker"。我已经完全按照书中给出的代码输入了代码,例如(我正在使用 MAC OS):

#! /usr/bin/env python3

# pw.py - An insecure password locker program.

PASSWORDS = {'email': 'JNAIBDUNOIH8937386SYB2G837DV37YD982DBS',
             'blog': 'VHUIDH782Y287S62W729SU29G17SGZ9HUih9hg',
             'luggage': '12345'}

import sys, pyperclip
if len(sys.argv) < 2:
    print("Usage: python pw.py [account] - copy account password")
    sys.exit()

account = sys.argv[1] # first command line arg is the account name.

if account in PASSWORDS:
    pyperclip.copy(PASSWORDS[account])
    print("Password for " + account + " copied to clipboard.")

else:
    print("There is no account named " + account)

然而,当我从终端 运行 它时,我得到一个错误。 我在终端中输入了这个:

chmod +x pw.py
./pw.py 

它有效并给我(如预期):

Usage: python pw.py [account] - copy account password

但是,当我输入 email or blog or luggage 时,我得到如下 error

zsh: command not found: email

有人可以帮助我吗?我挣扎了好几天。谢谢。

Python 脚本可以通过在命令前加上 pythonpython3:

来执行
python pw.py email

或使 pw.py 可执行文件(chmod +x pw.py)和 运行 作为脚本:

./pw.py email