无法扫描重复项列表

问题描述 投票:0回答:1

嘿所以我想扫描这个电子邮件的文本文件,如果弹出两个相同的电子邮件,我希望它打印,如果列表中只有一封电子邮件,我不希望它打印。

它适用于不同的文本文件,但现在它说跟踪错误???

#note make sure found.txt and list.txt are in the 'include' for pycharmfrom collect ions import Counter

print("Welcome DADDY")

with open('myheritage-1-million.txt') as f:
    c=Counter(c.strip().lower() for c in f if c.strip()) #for case-insensitive search
    for line in c:
        if c[line] > 1:
            print(line)

错误:

rs/dcaputo/PycharmProjects/searchtoolforrhys/venv/include/search.py
Welcome DADDY
Traceback (most recent call last):
  File "/Users/dcaputo/PycharmProjects/searchtoolforrhys/venv/include/search.py", line 5, in <module>
    c = Counter(c.strip().lower() for c in f if c.strip()) #for case-insensitive search
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 566, in __init__
    self.update(*args, **kwds)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 653, in update
    _count_elements(self, iterable)
  File "/Users/dcaputo/PycharmProjects/searchtoolforrhys/venv/include/search.py", line 5, in <genexpr>
    c = Counter(c.strip().lower() for c in f if c.strip()) #for case-insensitive search
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc5 in position 2668: invalid continuation byte

Process finished with exit code 1

在整个文本文件中显示2次的所有电子邮件列表

python traceback
1个回答
0
投票

关键是最后的错误消息:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc5 in position 2668: invalid continuation byte

尝试将非文本文件作为文本读取时,可能会发生此错误。您的文件可能会以某种方式损坏,并且其中包含一些无法作为文本读取的数据(位置2668)。

© www.soinside.com 2019 - 2024. All rights reserved.