将python 2模块转换为python3错误:“地图”类型的对象没有len()

时间:2018-08-23 09:03:22

标签: python python-3.x python-2.7

因此,我首先将pyggel转换为python 3,所有转换后的文件都在IDLE中运行没有问题,但是当我运行python 3中包含的游戏时,我遇到了此错误

GameObject.__init__(self, game, obj=pyggel.mesh.OBJ("data/gun.obj", 
colorize=[0.2, 0.2, 0.2, 1]),
File "/home/pi/Downloads/PYGGEL-V0.08-alpha4c/pyggel/mesh.py", line 58, 
in OBJ
cur_mtl.set_color(map(float, values[1:]))
File "/home/pi/Downloads/PYGGEL-V0.08-alpha4c/pyggel/data.py", line 355, in 
set_color
    if len(color) == 3:
 TypeError: object of type 'map' has no len()

这是错误产生的部分代码:

class Material(object):
"""A simple class to store a color and texture for an object."""
def __init__(self, name):
    """Create the material
       name is the name of the material"""
    self.name = name
    self.color = (1,1,1,1)
    self.texture = BlankTexture()

def set_color(self, color):
    """Set color of material."""
    if len(color) == 3:
        color += (1,)
    self.color = color

def copy(self):
    """Copy material."""
    a = Material(self.name)
    a.color = self.color
    a.texture = self.texture
    return a

更新我的问题不是重复的,我不是要找出列表的长度,否则“ if len()”语句是设置颜色的前提(这个模块在python 2.5中仍然有效)< / p>

1 个答案:

答案 0 :(得分:0)

先转换为列表

len(list(color))