python - 将 python 2 模块转换为 python3 错误:“map”类型的对象没有 len()
问题描述
因此,首先我将 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 中工作)
解决方案
首先转换为列表
len(list(color))
推荐阅读
- electron - 电子版 Gitlab CI 上的代码签名证书
- networking - 海龟在网络中选择路径
- javascript - javascript中的离散分布/样条比例
- sql - Woocommerce sql 产品订单价格
- python - django模型的继承
- python - 类型错误:addRecord() 缺少 1 个必需的位置参数:'val9'
- javascript - Java脚本回调不同步
- c++ - C++ 我的 Gauss–Seidel 方法不能很好地工作
- android - TextAppearance 覆盖样式的 fontFamily
- google-app-engine - 在 GAE 中可以知道请求的地理位置吗?