如何将多个列表从一个变量变成一个列表(odoov11)?
How to turn multiple lists from one variable into one list (odoov11)?
我有一个字段:
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']
我做错了什么?
def _compute_sum_50(self):
x = [record.overtime_50for record in self] # Use List Comprehension
print(x)
编辑:Dipen Shah 提供的更好的解决方案
我有一个字段:
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']
我做错了什么?
def _compute_sum_50(self):
x = [record.overtime_50for record in self] # Use List Comprehension
print(x)
编辑:Dipen Shah 提供的更好的解决方案