Search code examples
pythonpyodbc

Pass data to a varaible with pyodbc


I connected to a database and there are some datas in it.

In here I print the name of the person whose id is 2

cursor.execute('Select Name from Customers Where Id = 2')
for row in cursor:
    print(row)

The name of the person is "Alex" it this code is being printed like this

('Alex', )

I want to pass this name "Alex" to a varaible and then when i print it I want it to be look like

print(name)

answer

Alex

How can I do it?


Solution

  • print(row[0])
    

    It is a tuple, so extract so first element from it.