콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
4468 화면

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]]

관련 게시물 답글 화면 활동
3
8월 15
22969
1
3월 15
6537
0
2월 16
3107
2
8월 15
6857
1
8월 15
4862