通过python连接MySQL并给变量赋值时,数据类型由'int'变为'tuple'

Through python when connecting MySQL and assign vales to variables, datatype changed from 'int' to 'tuple'

python 和 mysql 都比较新。

我已经解决了这个问题,但想知道原因。如果我在将值分配给变量后使用 'comma',那么它会将下一个数据类型从 'int' 更改为 'tuple'。对于刺痛它不是。如果我在每行之后省略 'comma' ,那么数据类型将保持不变。在这两种情况下,代码 exec 都没有 'Exception'。

DB 输入数据类型为:func_Name 为 varchar,nbin 为 int,winWidth 为 int,ashFilt 为 varchar 等

部分代码:-

cursor.execute("SELECT * FROM func_table;")
tab_funcTab = cursor.fetchall()
    print("parameters in [func_table]: ", cursor.rowcount)
    for row in tab_funcTab:
        funcName =      (str(row['func_Name'])), # <- this commas
        nbin =          (int(row['nbin'])), # <- this commas
        winWid =        (int(row['winWidth'])),
        ashFilt =       (str(row['ashFilt']))

     print(tab_funcTab)
     [{'id': 1, 'func_Name': 'all', 'nbin': 100, 'winWidth': 5, 'ashFilt': 'biweight']   

     print(type(funcName), type(nbin), type(winWid), type(ashFilt))
     <class 'str'> <class 'tuple'> <class 'tuple'> <class 'str'>

有人能解释一下原因吗?

在值后使用逗号将准确地创建一个元组。我已经用 python2 和 3 再次测试了你的代码。你需要再次检查它。