首先要了解什么是命令行参数
1 2 | import sys,os os.system(sys.argv[ 1 ]) |
#这个例子os.system接收命令行参数,运行参数指令,
# cmd命令行带参数运行python 当前文件夹名称.py notepad,将打开记事本程序。
1 2 3 4 5 6 7 8 9 10 11 12 13 | PASSWORD = { ‘QQ‘ : ‘452212889‘ , ‘email‘ : ‘maojiaxu@yeah.net‘ } import sys,pyperclip if len (sys.argv)< 2 : print ( ‘Usage: py pw.py[account] -copy account password‘ ) sys.exit() account = sys.argv[ 1 ] if account in PASSWORD: pyperclip.copy(PASSWORD[account]) print ( ‘Password for‘ + account + ‘copied to clipboard.‘ ) else : print ( ‘There is no account named ‘ + account) |
桌面创建一个pw.bat脚本
1 2 | @py.exe E:\Code\Python\pw.py %* @pause |
配置环境变量
在cmd 执行 pw + 参数
原文:http://www.cnblogs.com/mjxup/p/43cb70daffd99f9590fa718205bbe967.html