search

Home  >  Q&A  >  body text

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
        ……
PHPzPHPz2892 days ago536

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 09:25:17

    I don’t quite understand your question

    But [obj] is just a list, so of course it can be iterated!


    Questions I answered: Python-QA

    reply
    0
  • Cancelreply