【发布时间】:2021-10-26 13:52:08
【问题描述】:
我有一个字段:
overtime_50 = fields.Char(readonly=True, default='00:00')
我列出了这个字段,我得到了很多列表:
def _compute_sum_50(self):
for record in self:
x = [record.overtime_50]
print(x)
控制台打印:
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
我需要像这样得到一些东西:
['00:00','00:00','00:00','00:00','00:00','00:00','00:00','00:00','00:00']
我尝试了很多方法,但我只能得到这样的结果:
def _compute_sum_50(self):
for record in self:
x = [record.overtime_50]
print(list(chain.from_iterable(x)))
控制台打印:
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
我能做错什么?
【问题讨论】:
-
在每次迭代中,您重新分配
x,当您真的想追加到它时。一旦你弄清楚如何做到这一点,你可能还想看看理解。
标签: python list odoo python-3.6