Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
4333 มุมมอง

I have a list which collect data, and at one point it returns None and i need to replace this None with a 0. How can i get this done in openerp 7

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can iterate the list and check the condition. If you get None value it will insert 0 in new list.

>>> a = [1,2,3,'c',None]

>>> b = []

>>> for x in a:

... if x is None:

... b.append(0)

... else:

... b.append(x)

...

>>> b

[1, 2, 3, 'c', 0]

อวตาร
ละทิ้ง
ผู้เขียน

Thank You @Krutarath,

Already i have done that this way,

late_duration = [['a', 1], ['b', 4], ['c', None]]

late_duration_val_list = [[None if isinstance(b, int) else 0 if b == None else b for b in i] for i in late_duration]

late_duration.append(late_duration_val_list)

print (late_duration_val_list)

Output is,

[['a', None], ['b', None], ['c', 0]]

Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ส.ค. 15
22787
1
มี.ค. 15
6380
0
ก.พ. 16
2998
2
ส.ค. 15
6750
1
ส.ค. 15
4717