【发布时间】:2018-04-11 13:55:23
【问题描述】:
正在尝试使用“使用 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)
【问题讨论】:
-
这是一个猜测,但它是否需要一个字符串,您试图在其中复制
int。如果你通过str(PASSWORD[account]),你会得到同样的错误吗? -
好吧,现在我觉得自己很愚蠢,因为没有看到这一点。非常感谢!如果你把它作为一个答案,我可以投票给你。
标签: python pyperclip argument-error