python - 为什么长文本文件在 Spyder 中不起作用?
问题描述
我正在开发一个需要长文本文件(键盘密码解码器)的程序,并且正在使用 Spyder。它表示无法检索某个位置的内存。我尝试将文本文件和程序放在同一个文件夹中。这是 spyder 本身的问题还是我的代码的问题?对于上下文,.txt 文件有大约 500,000 个字符(100,000 个最常用的单词)。
with open("wiki-100k.txt") as word_file:
english_words = set(word.strip().lower() for word in word_file)
def IsWord(word):
return word.lower() in english_words
print(IsWord("HaMs"))
我收到此错误:
Traceback (most recent call last):
File "C:\Users\eirta\Desktop\Ciphers\Keypad.py", line 3, in <module>
english_words = set(word.strip().lower() for word in word_file)
File "C:\Users\eirta\Desktop\Ciphers\Keypad.py", line 3, in <genexpr>
english_words = set(word.strip().lower() for word in word_file)
File "C:\Users\eirta\anaconda3\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 2814: character maps to <undefined>
解决方案
推荐阅读
- regex - 如何使用正则表达式替换带有问号的句子
- django - Django - 强制用户密码重置/过期
- javascript - 如何访问数组 reduce 中的循环参数
- c# - C#将对象序列化为xml而不格式化
- for-loop - XSLT 中的嵌套 for 循环
- django - 自定义视图集中不允许使用 POST 方法
- javascript - 如何使用 ExpressJS 通过 HTML 页面控制(启动、中止)外部程序?
- reactjs - 替换选中的文本并在草稿js中添加链接
- amazon-web-services - isclient.config.discovery.NodeChecker:执行 NodesInfo 时出错
- c# - Word interop C# Range 中的非中断连字符