栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python AttributeError: ‘map‘ object has no attribute ‘extend‘

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python AttributeError: ‘map‘ object has no attribute ‘extend‘

C:UserskaiDesktopCRC32-1-6位>python3 crc321-6.py
verification checksum: 0x308e1d5b (OK)
Traceback (most recent call last):
  File "C:UserskaiDesktopCRC32-1-6位crc321-6.py", line 3, in 
    crc32_reverse(0x308e1d5b,4)
  File "C:UserskaiDesktopCRC32-1-6位my_crc32.py", line 129, in crc32_reverse
    obj.run_reverse()
  File "C:UserskaiDesktopCRC32-1-6位my_crc32.py", line 109, in run_reverse
    patch.extend(last_4_bytes)
AttributeError: 'map' object has no attribute 'extend'
            for item in self.dfs(self.length - 4):
                patch = map(ord, item) ###Python 2.x 返回列表。
                patches = self.findReverse(desired, self.calc(patch, accum))
                for last_4_bytes in patches:
                    if all(p in self.char_set for p in last_4_bytes):
                        patch.extend(last_4_bytes)
                        print ('[find]: {1} ({0})'.format('OK' if self.calc(patch, accum) == desired else 'ERROR', ''.join(map(chr, patch))) )

这里就有一个问题,对于map()函数的用法,在python2和3中的有些许差别,也就导致无法后续继续调用计算:
map() 函数语法:
map(function, iterable, …)
参数
function – 函数
iterable – 一个或多个序列
返回值
Python 2.x 返回列表。
Python 3.x 返回迭代器。

所以需要把 patch = map(ord, item)修改成patch = list(map(ord, item) )

要把map函数返回的迭代器转换为列表(list),这就是由于python2,Python3版本不同偏差

            for item in self.dfs(self.length - 4):
                patch = list(map(ord, item) )###  map(ord, item),Python 3.x 返回迭代器。
                patches = self.findReverse(desired, self.calc(patch, accum))
                for last_4_bytes in patches:
                    if all(p in self.char_set for p in last_4_bytes):
                        patch.extend(last_4_bytes)
                        print ('[find]: {1} ({0})'.format('OK' if self.calc(patch, accum) == desired else 'ERROR', ''.join(map(chr, patch))) )

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/935318.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号