【发布时间】:2020-11-02 22:38:10
【问题描述】:
我有一段代码可以做到这一点:
def number(self, width = None):
if not self.v:
return None
if not width:
width = len(self.v)
return self.VERSION_DELIMITER.join(map(str, self.v[:width]))
我最近改用 Python 3 而不是 2。当我这样做时,我开始收到错误:
TypeError: 'map' object is not subscriptable:
在 Python 3 中进行这项工作的最佳方法是什么?
【问题讨论】:
-
您能否分享
self.v和width的值的示例以及您期望获得这些值的输出? -
请编辑您的问题以包含minimal reproducible example。
标签: python python-3.x