I use globals() to create p1,p2,...variables. However when I call these variables, the code analysis gives me error hint saying those variables are non-existence. It seems like the code analysis does not recognize the variables not created explicitly. Although the code can run without any problem, but I still want to get ride of them. The code is as:
def save_new_element(self,ui_main_window,dp,pltr,selected_module):
# assign factors for analysis
for i in range(27):
if i < 9: # comboBox 1~9
globals()[f'p{i+1}'] = eval('ui_main_window.comboBox_%d_prsnlf' % (i+1)).currentText()
else: # comboBox 14~31
globals()[f'p{i+1}'] = eval('ui_main_window.comboBox_%d_prsnlf' % (i+5)).currentText()
conn = sqlite3.connect('data.db')
c = conn.cursor()
c.execute("SELECT 员工编号 FROM personel WHERE 员工编号 = (?)",(ui_main_window.lineEdit_9_prsnlf.text(),))
t1 = c.fetchall()
if len(t1) > 0: # record exists, delete first
c.execute("DELETE from personel WHERE 员工编号 = (?)",(ui_main_window.lineEdit_9_prsnlf.text(),))
c.execute("""INSERT INTO personel VALUES(?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,?)
""",
(ui_main_window.lineEdit_1_prsnlf.text(),ui_main_window.lineEdit_2_prsnlf.text(),
ui_main_window.lineEdit_3_prsnlf.text(),ui_main_window.lineEdit_4_prsnlf.text(),
ui_main_window.lineEdit_5_prsnlf.text(),ui_main_window.lineEdit_6_prsnlf.text(),
ui_main_window.lineEdit_7_prsnlf.text(),ui_main_window.lineEdit_8_prsnlf.text(),
ui_main_window.lineEdit_9_prsnlf.text(),
p1,p2,p3,p4,p5,p6,p7,p8,p9,
ui_main_window.comboBox_10_prsnlf.currentText(),ui_main_window.comboBox_11_prsnlf.currentText(),
ui_main_window.comboBox_12_prsnlf.currentText(),
ui_main_window.comboBox_13_prsnlf.currentText(),
p10,p11,p12,p13,p14,p15,p16,p17,p18,
p19,p20,p21,p22,p23,p24,p25,p26,p27,
ui_main_window.comboBox_32_prsnlf.currentText()))
Rvalue,basic1,b1,b4,capacity1,pyhsi1,psych1,behave1 = dp.calculate_values_personel(p3,p4,p5,p6,p7,p8,p9,p2,p1,p10,p11,p12,p13,p14,p15,
p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,p26,p27)
self.alertSounds(Rvalue)
ui_main_window.AGwidget_prsnlf.updateValue(Rvalue)
self.temp_stat_prsnlf.loc[0] = [Rvalue,basic1,b1,b4,capacity1,pyhsi1,psych1,behave1,Rvalue]
pltr.plotRadar(ui_main_window,self,dp,selected_module)
ui_main_window.label_radar_prsnlf.setPixmap(QtGui.QPixmap(self.pic_dir_prsnlf))
conn.commit()
conn.close()