8
我有一個名爲元組,我值分配給這樣的:循環通過命名元組的元素在python
class test(object):
self.CFTs = collections.namedtuple('CFTs', 'c4annual c4perren c3perren ntfixing')
self.CFTs.c4annual = numpy.zeros(shape=(self.yshape, self.xshape))
self.CFTs.c4perren = numpy.zeros(shape=(self.yshape, self.xshape))
self.CFTs.c3perren = numpy.zeros(shape=(self.yshape, self.xshape))
self.CFTs.ntfixing = numpy.zeros(shape=(self.yshape, self.xshape))
有沒有辦法來遍歷命名元組的元素?我試着這樣做,但不工作:
for fld in self.CFTs._fields:
self.CFTs.fld= numpy.zeros(shape=(self.yshape, self.xshape))
謝謝@Pawel,好的點不變性。任何方式,你可以適應你的迴應我的具體代碼? – user308827
只是用自己替換.CTF –
我沒有在python3上找到_asdict屬性,我使用了'argp .__ dict __。items()'而不是 – ThorSummoner