正在尝试使用“使用 Python 自动化无聊的东西”一书中的 pyperclip 进行一些简单的代码练习,但是在尝试使用命令行运行程序时,我一直遇到以下错误。
尝试在网上寻找无济于事:我尝试使用 pip 命令行重新安装 pyperclip,将init .py 文件复制到主要 Python 文件夹并将文件名更改为 pyperclip,但到目前为止没有任何效果。非常感谢您支持了解这里的问题以及如何解决它。
错误如下:
Traceback (most recent call last):
File C:\Users\AppData\Local\Programs\Python\Python36-32\pw.py, line 15, in <module>
pyperclip.copy(PASSWORD[account])
File C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyperclip\_init_.py", line 424, in copy_windows
count = wcslen(text) + 1
File C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyperclip\_init_.py", line 304, in_call_
ret = self.f(*args)
ctypes.ArgumentError: argument 1: <class 'TYpeError'>: wrong type
代码如下:
#! python3
# pw.py - An insecure password locker program
PASSWORD = {'email':1234,'facebook':5678}
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 PASSWORD:
pyperclip.copy(PASSWORD[account])
print('Password for ' + account + ' copied to clipboard')
else:
print('There is no account named ' + account)