Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2669 Lượt xem

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'


Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 10 23
6417
2
thg 11 22
6802
0
thg 9 21
2903
4
thg 8 20
7732
2
thg 3 20
11594