首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模块'caesar‘没有'alphabet’属性

模块'caesar‘没有'alphabet’属性
EN

Stack Overflow用户
提问于 2020-01-30 13:55:40
回答 1查看 41关注 0票数 0

我是Python的新手,我不认为我完全理解我得到的'no attribute‘错误消息,我想知道是否有人能给我一些提示,或者更好地解释我在'alphabet’变量中遗漏了什么。

代码语言:javascript
复制
import caesar

def loadDictionary():
        dictionary = {}
        file = open('dictionary.txt')

        for word in file.read().split('\n'):
        dictionary[word.upper()] = None

        file.close
        return dictionary

DICTIONARY = loadDictionary()

        def isEnglish(plaintext):
        matchingWords=0
        words = plaintext.split(' ')
        for word in words:
            if word.upper() in DICTIONARY:
            matchingWords += 1

        return matchingWords / len(words) >= 0.6

def bruteForce(cihertext):
        for key in range(len(caesar.alphabet)):
        plaintext = caesar.caesar(ciphertext, key, 'd')
        if isEnglish(plaintext):
        print('Key: ' + str(key) + 'Plaintext = ' + plaintext)

        return None

ciphertext = 'Qefp'
bruteForce(ciphertext)
EN

回答 1

Stack Overflow用户

发布于 2020-01-30 14:05:26

这意味着caesar模块不包含任何叫做“字母表”的东西。在文档或其源代码中查找正确的名称。考虑到在python中,所有变量名都是区分大小写的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59979860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档