pythonmysqltuplesconnectorfetchall

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


Comparatively new in both python and mysql.

I have solved the issue, but want to know the reason. If I use 'comma' after assigning the values to the variables, then it is changing the next datatype from 'int' to 'tuple'. For sting it is not. If I omit the 'comma' after each line then datatype remains as they are casting. In the both the cases, code exec without 'Exception'.

The DB input datatype are: func_Name as varchar, nbin as int, winWidth as int, ashFilt as varchar etc.

part of the code:-

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'>

Could someone pl explain the reason?


Solution

  • Using comma after value will exactly create a tuple. I have tested your code again with both python2, and 3. You need to check it again.