解决公式内的数据进行正确判断的问题,初次使用Try

界面参数已经通过model.record(i).value(j)通过循环枚举取得。

# 清空标准数据重新写入计算参数函数:
def clear_x_add(self):
    self.zj_parameter.clear()  # 清空列表
    self.list_x = []
    # 将model的数据拿出来至list_data
    row_n = table_model.rowCount()
    column_n = table_model.columnCount()
    list_data = pd.DataFrame(index=range(row_n), columns=range(column_n))
    for i in range(row_n):
        for j in range(column_n):
            list_data.loc[i, j] = table_model.record(i).value(j)
    get_x_list = list_data[list_data.columns[4:6]]  # 我只需要4,5列
    print(get_x_list)

    # 用正则表达式找出自己需要参数,当然先要import re
    get_x_compile = re.compile("[a-z]\'|[a-z]|[A-Z]")
    for n in get_x_list[4] + get_x_list[5]:  # python福利:列表相加
        add_item = re.findall(get_x_compile, n)
        for m in add_item:
            if m not in self.list_x:  # python福利:有不同元素就放入
                self.list_x.append(m)
                self.zj_parameter.appendPlainText(m + '=')  # 顺便将数据写入列表
            if 'H' not in self.list_x:
                self.zj_parameter.appendPlainText('H')
    print(self.list_x)

对文本框写入的公式需要进行=号前后数据判断:

>>> a
'33'
>>> b
33.33
>>> 
>>> 
>>> 
>>> def check_a(x):
...     try:
...             if x.isdigit() is True:
...                     print('True')
...             else:
...                     print('False')
...     except:
...             print('Data Wrong',type(x))
... 
>>> 
>>> 
>>> 
>>> check_a(a)
True
>>> a.isdigit()
True
>>> 
>>> 
>>> check_a(b)
Data Wrong <class 'float'>
>>> 
>>> 
>>> 
>>> 
>>> check_a(c)
False
>>> c
'this is string'

以上为自己写的Try也是将测试进行一个初步开始。