0

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.

6
  • 1
    Do you have py.exe? The usual name of the Python interpreter on Windows is python.exe. Commented Jul 31, 2019 at 5:55
  • after reading the answer, yes I have it installed Commented Jul 31, 2019 at 6:31
  • 1
    You are aware that only the bottom two lines of your code are for the batch-file aren't you? Commented Jul 31, 2019 at 7:40
  • yes, I just figured that out Commented Jul 31, 2019 at 8:29
  • how do I open .bat file? I clicked on it and it states press any key to continue and upon pressing any key it exits the program. Commented Jul 31, 2019 at 8:30

1 Answer 1

1

Here are troubleshooting steps I'd suggest:

  1. 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.

  2. 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.

  3. 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.

Sign up to request clarification or add additional context in comments.

3 Comments

Okay, I guess the second part was the problem.
how do I open .bat file? I clicked on it there is nothing shown there. Just stating press any key to continue and upon pressing any key it exits the program.
Two ways: (a) double clicking (which is what you did). It shows the output followed by what you mention ("press any key to continue") which is the result of @pause, (b) open a command prompt, go to the location where your batch file is (via command 'cd <your/batch/file's/path>'), run the batch file by typing the name of the batch file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.