def fmt(obj, nest_level=0):
""" Format any common object """
if nest_level > 10:
return ""
if isinstance(obj, float):
return "{0:.3f}".format(obj)
if isinstance(obj, list):
return "(" + ",".join(map(lambda x: fmt(x, nest_level + 1), obj)) + ")"
if isinstance(obj, (numpy.ndarray, numpy.generic)):
return fmt(obj.tolist(), nest_level + 1)
if isinstance(obj, dict):
pairs = map(lambda x, y: "(" + fmt(x) + "," + fmt(y, nest_level + 1) + ")", obj.items())
return fmt(pairs)
if isinstance(obj, Vector3):
return "({},{},{})".format(fmt(obj.x), fmt(obj.y), fmt(obj.z))
if isinstance(obj, Quaternion):
return "({},{},{},{})".format(fmt(obj.x), fmt(obj.y), fmt(obj.z), fmt(obj.w))
# print " obj " + str(obj) + " is of type " + str(type(obj))
return str(obj)
评论列表
文章目录