python 对象数组

需要a=['Face object','Face object']这种形式,a[1]只是Face object的内容比如>>> print a[1]
({'featureName': None, 'index': 1, 'instanceName': 'A-Bushing_s-20151111-1', 'isReferenceRep': False, 'pointOn': ((-1.268087, -19.208438, -16.0),)})
abaqus 二次开发

类中声明一个__str__函数,用来返回类的字符串输出格式

class Face():
    featureName = None
    index  = 1
    instanceName ='A-Bushing_s-20151111-1'
    isReferenceRep = False
    pointOn = ((-1.268087, -19.208438, -16.0),)
    
    def __str__(self):
        #这里你可以根据需要拼装s变量
        s = "({'featureName': None, 'index': 1, 'instanceName': 'A-Bushing_s-20151111-1', 'isReferenceRep': False, 'pointOn': ((-1.268087, -19.208438, -16.0),)})"
        return s
a = [Face(),Face()]
print(a[1])

追问

这个问题我已经解决了,用数组切片即可:print a[0:1],分还是给你吧

温馨提示:答案为网友推荐,仅供参考
相似回答