我一直收到这个错误,而且我是Python的新手,所以我不确定我做错了什么。这段代码基本上是从我正在学习的书中复制出来的,不会运行。
错误消息:
Traceback (most recent call last):
File "C:\Users\RaudaR\Desktop\Work\python_work\phoneAndEmail.py", line 23, in <module>
text = str(pyperclip.paste())
AttributeError: module 'pyperclip' has no attribute 'paste'下面是我正在运行的Atom代码。
#! python3
# phoneAndEmail.py - Finds phone numbers and email addresses on the clipboard.
import pyperclip, re
phoneRegex = re.compile(r'''(
(\d{3}|\(\d{3}\))? # area code
(-|\s|\.)? # separator
(\d{3}) # first 3 digits
(-|\s|\.) # separator
(\d{4}) # last 4 digits
(\s*(ext|x|ext.)\s*(\d{2,5}))? # extension
)''', re.VERBOSE)
# Create Email Regex.
emailRegex = re.compile(r'''(
[a-zA-Z0-9._%+-]+ # username
@ # @ symbol
[a-zA-Z0-9.-]+ # domain name
(\.[a-zA-Z]{2,4}) # dot-something
)''', re.VERBOSE)
# Find Matches in Clipboard text.
text = str(pyperclip.paste())
matches = []
for groups in phoneRegex.findall(text):
phoneNum = '-'.join([groups[1], groups[3], groups[5]])
if groups[8] != '':
phoneNum += ' x' + groups[8]
matches.append(phoneNum)
for groups in emailRegex.findall(text):
matches.append(groups[0])
# Copy results to the Clipboard.
if len(matches) > 0:
pyperclip.copy('\n'.join(matches))
print('Copied to clipboard:')
print('\n'.join(matches))
else:
print('No phone numbers or email addresses found.')该模块与phoneAndEmail.py位于同一文件夹中,它修复了我之前的一个导入问题。
发布于 2020-10-17 10:04:52
您需要从工作目录签入一些内容。
pyperclip.py或pyperclip.pyc的文件可能会被导入,而不是实际的pyperclip library.如果这对你不起作用,你可以使用pip uninstall pyperclip,然后重新安装pip install pyperclip。
发布于 2020-05-16 00:27:35
您有没有自己创建的一个名为pyperclip.py的文件?也许它(或它的.pyc版本)是意外进口的- Tadhg McDonald-Jensen Dec 16 '16 at 18:57
这对我很有效。
https://stackoverflow.com/questions/41190341
复制相似问题