Issue
Have multiply if statements for my error output in project. Can it be simplified?
if self.Lot_Mean_r<=0 or self.Lot_SD_r<=0 or self.SSB_DF_r<=0 or self.SSW_DF_r<=0 or self.SST_DF_r<=0:
if self.Lot_Mean_r<=0:
self.ui.textEdit_status_N.append("Error: Lot Mean negative or less than 0")
if self.Lot_SD_r<=0:
self.ui.textEdit_status_N.append("Error: Lot SD negative or less than 0")
if self.SSB_DF_r<=0:
self.ui.textEdit_status_N.append("Error: SSB DF negative or less than 0")
if self.SSW_DF_r<=0:
self.ui.textEdit_status_N.append("Error: SSW DF negative or less than 0")
if self.SST_DF_r<=0:
self.ui.textEdit_status_N.append("Error: SST DF negative or less than 0")
else: [main code]
Solution
One possible way would be to go with a dict :
attr_dict = {"Lot Mean": self.Lot_Mean_r,
"Lot SD": self.Lot_SD_r,
"SSB DF": self.SSB_DF_r,
"SSW DF": self.SSW_DF_r,
"SST DF": self.SST_DF_r}
for key, value in attr_dict.items() :
if value <= 0 :
self.ui.textEdit_status_N.append(f"Error: {key} negative or less than 0")
Answered By - RandomGuy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.