通过MySQL,当连接MySQL并将变量赋值时,数据类型从'int'变为'tuple'

问题描述 投票:0回答:1

在python和mysql中都比较新。

我已经解决了问题,但想知道原因。如果在将值分配给变量后使用“逗号”,则它将下一个数据类型从“ int”更改为“ tuple”。 st不是。如果我在每行之后省略“逗号”,则数据类型将保持不变。在这两种情况下,代码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'>

有人可以解释原因吗?

python mysql tuples connector fetchall
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.