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

Hello forks,

Could someone help me correct this onchange code. I have a predefined values with different datatype. My code works fine if result value and predefined value are float datatype. But when inputted value is outside float i get an error.

Expected result values are float, integer, char, text.

How can i make it to work? Below is my onchange code

@api.onchange('normal_range', 'result')
def onchange_result(self):
    if self.normal_range:
        no1,no2 = self.normal_range.split('-')
        if self.result:
            if float(self.result) >= float(no1) and float(self.result) <= float(no2):
                self.remark = 'Normal'
            elif float(self.result) <= float(no1):
                self.remark = 'Below'
            elif float(self.result) >= float(no2):
                self.remark = 'Above'


아바타
취소

please share the error here and try doing debuging and urself u can find the answer,

and if your inputs are in digits python have no trouble making it to float

베스트 답변

Try to use is instance function of python. which help you to check data type.

아바타
취소
관련 게시물 답글 화면 활동
2
10월 23
6559
2
11월 22
6980
0
9월 21
3048
4
8월 20
7896
2
3월 20
11824