mycursor.execute("SELECT Name FROM employee_details")
names = (mycursor.fetchall())
for y in names:
print (y)
Result:
('dsf',)
('Gai',)
('egw',)
('qwr',)
('Sam',)
Result I want:
dsf
Gai
egw
qwr
Sam
mycursor.execute("SELECT Name FROM employee_details")
names = (mycursor.fetchall())
for y in names:
print (y)
Result:
('dsf',)
('Gai',)
('egw',)
('qwr',)
('Sam',)
Result I want:
dsf
Gai
egw
qwr
Sam
cursor.fetchall()
return list of tuples. you can access single values from tuple using index.
for y in names:
print (y[0])
Add a comma after the loop value in the for
statement, to assign a name to the element in the tuple, and omit the comma when printing, to get only the element:
for y, in names:
print(y)
As @deadshot mentions in the comments, this works because of Python's tuple-unpacking syntax. It's no different to
a, b = (1, 2)
except that there is a single-element tuple involved, and we tend to think of tuples as having more than one element
a, = (1,)
You can save result to string and replace ('') with " ". This is easy way to do it :D.
String = result.replace("('", "")
String = String.replace("')", " ")