The book on a topic need to implement the function "according to the account password, copy password to the Clipboard." The account number and password are stored in the code dictionary.
Problem Description:
As a python novice from the code (see below) only know:
1. SYS.ARGV initially contains a row of file paths.
2. The account to be queried needs to be transferred to SYS.ARGV.
How does it work?
#! Python3#pw.py-an inssecure Password locker program.#Run This program in CMD, the parameter (account) load after filename. Like:pw.py EmailPasswords={'Email':'F7minlbdduvjjux','Blog':'VmALvWyKAxiVH5','Luggage':'12345'}ImportSys,pyperclipifLensys.argv)<2: Print('Usage:python pw.py [Account]-Copy account password') Sys.exit () account=Sys.argv[1] #First command line ARG was the account nameifAccountinchPASSWORDS:pyperclip.copy (Passwords[account])Print('Password for'+account+'copied to clipboard.')Else: Print('There is no account named'+Account )
Solution Ideas:
command-line arguments, which are manipulated by the command line.
In the CMD CD to pw.py directory, the parameter is placed after the file name when the command is hit. Like, it's done.
d:\div\pyscripts>Blog for blog copied to clipboard. D:\DIV\PyScripts>luggage for luggage copied to clipboard. D:\DIV\PyScripts>email for e -mail copied to clipboard. D:\DIV\PyScripts>
Note:
SYS.ARGV imports with import, the initial value is the path of the running file + filename, the account value after the incoming account is added to the SYS.ARGV, as follows:
['d:\\div\\pyscripts\\pw.py'email']
When the program finishes running, it tries to print sys.argv, and the passed parameters are freed.
The above is a novice python for sys.argv a little superficial understanding, if there is no understanding of the place, welcome to correct.
[Python] sys.argv command line arguments passed in