自动化无聊的东西第6章:密码锁

时间:2019-02-26 04:21:58

标签: python

#! python3
#pw.py - An insecure password locker program.
PASSWORDS = {'email' : 'JKL:DF234@#$',
             'twitter' : 'asd;lfjk@#$',
             'youtube' : 'as;ldkjf;sljf234'}

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 ' + account + ' copied to clipboard.')
else:
    print('There is no account named ' + account)

@py.exe C:\Users\Path\To\File %*
@pause

我是python的新手,试图弄清楚为什么它不起作用。我的@ py.exe部分不断出现语法错误,我不确定为什么。任何帮助将不胜感激。

"C:\Users\rowla\PycharmProjects\Password Locker\venv\Scripts\python.exe" "C:\Users\rowla\PycharmProjects\Password Locker\Password Locker.py"
  File "C:\Users\rowla\PycharmProjects\Password Locker\Password Locker.py", Line 22
    @py.exe C:\Users\rowla\AppData\Local\Programs\Python\Python37-32\PythonScripts %*
            ^
SyntaxError: invalid syntax

2 个答案:

答案 0 :(得分:1)

就像@Andreas的评论一样,@py.exe ...不是有效的Python。您应该有一些pw.py之类的python模块,其中包含内容

#! python3
#pw.py - An insecure password locker program.
PASSWORDS = {'email' : 'JKL:DF234@#$',
             'twitter' : 'asd;lfjk@#$',
             'youtube' : 'as;ldkjf;sljf234'}

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 ' + account + ' copied to clipboard.')
else:
    print('There is no account named ' + account)

然后在命令行中运行

py.exe C:\Users\path\to\pw.py email
py.exe C:\Users\path\to\pw.py not_in_locker

如果您将Python安装在PATH上(即python --version不会引发某些错误),则可以改为调用

python C:\Users\path\to\pw.py email

答案 1 :(得分:0)

以下部分不属于您的python程序:

@py.exe C:\Users\Path\To\File %*
@pause

使用上面的命令创建一个.bat批处理文件,然后将该文件添加到系统路径 Windows,以便您可以从“运行”对话框中运行它。