Reputation: 1927
I am studying automate the boring stuff with python
book and therein after finishing the password locker
project it is suggested to create a batch file using the following codes:
@py.exe C:\Python34\pw.py %*
@pause
and I did exactly the same mine one looks like this (copied entire script if there are any other potential errors):
import sys
import pyperclip
""" PASSWORD LOCKER """
passwords = {
'facebook' : 'password of facebook',
'gmail' : 'password of gmail',
'quora' : 'password of quora'
}
if len(sys.argv) == 2:
account_name = sys.argv[1]
if account_name in passwords:
print('Password of [' + str(account_name).upper() + '] has been copied to clipboard.')
acc_password = passwords[account_name]
pyperclip.copy(acc_password)
print('Paste it anywhere')
else:
print('There is no name registered with that account name.')
@py.exe 'C:\py\Automate the Boring Stuff with Python\Data Structures, Dictionary\pw.py' %*
@pause
then saved the file as pw.bat
, according to instruction of the book:
With this batch file created, running the password-safe program on Windows is just a matter of pressing win-R and typing pw .
I then followed these steps again and it didn't work fine. Can you please help me with this. Thank you.
Upvotes: 0
Views: 222
Reputation: 338
Here are troubleshooting steps I'd suggest:
Ensure py.exe
exists in environment path of your computer. The book may have installation instructions that may have been skipped inadvertently. If you know py.exe
exists on your computer, but when you execute py.exe
on opening a command prompt, you may see:
'py.exe' is not recognized as an internal or external command, operable program or batch file.
If you see the above message, this implies, you need to do either of the following:
a. Change your batch file to say:
`@<drive:\path\to>\py.exe`
where the part <drive:\path\to>
is the path to your python executable (py.exe
), OR,
b. Add the path to py.exe
to the environment variables. Comprehensive instructions are here for Python 3.
The way you have framed the question seems to suggest that you saved the entire code in one file pw.bat
. If you did, you need to ensure the following:
a. Last two lines of the your code snippet are in a file pw.bat
, AND,
b. Rest of the code is in the file C:\py\Automate the Boring Stuff with Python\Data Structures, Dictionary\pw.py
.
The instruction below is correct only if the file pw.bat
is in the environment path and thus visible to the operating system:
With this batch file created, running the password-safe program on Windows is just a matter of pressing win-R and typing pw
If you do not know whether this is true or not, you will need to find out where you saved pw.bat
. Open a command prompt and navigate to that location, and then execute pw
. Issues pertinent to this are discussed here.
Upvotes: 1