Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading