首页 > Python中对象作为元素组成列表问题,[obj]代表什么含义?

Python中对象作为元素组成列表问题,[obj]代表什么含义?

1.下面这行代码中,[obj]是对象列表吗?没有读懂下面代码的这一处。
从运行上看,[obj]的确是可迭代的iterable。

在run.py中

obj=TR_OBJ(seq,labels,name=sys.argv[1]) 
tr_obj_list=[obj]

for o in tr_obj_list:    #    obj仅仅是一个对象吗?
    do_something(o.seq)

关于TR_OBJ的类定义

class TR_OBJ:
    ''' define a trainable object, a TR_OBJ object cositst of: 
        self.seq    # the list of symbols || vectors
        self.labels    # the list of the labels
        self.name    # the object name
        ……
    '''

    def __init__(self, seq, labels=[], f=[], b=[], eMat=[], scale=[], p=None, name=None):
        self.seq = seq          # the list of symbols || vectors
        self.labels = labels    # the list of the labels
        self.name = name        # the object name
        ……

不是很懂你的問題

不過 [obj] 就是一個 list, 那他當然可以迭代囉!


我回答過的問題: Python-QA

【热门文章】
【热门文章】