Reputation: 43
I am trying to get country names from database and paste them to QComboBox. Everything working fine except that tuples coming out of db table like ('Afghanistan',) , ('Angola',) ... The question is how to delete that unuseful characters from tuples. The code is:
countries = []
try:
conn = MySQLdb.connect(host='localhost', user='root', passwd='*****', db='world')
cursor = conn.cursor()
try:
cursor.execute("SELECT Name from country")
while True:
rows = cursor.fetchone()
if rows == None:
break
else:
countries.append(rows)
except:
print('Error CURSOR')
cursor.close()
conn.close()
except:
pass
for i in countries:
self.country_cbox.addItem(str(i)) # Converting to string
print(countries)
self.add_worker.show()
self.add_worker.exec_()
Upvotes: 0
Views: 51
Reputation: 4302
You can use column name or tuple index to delete value:
countries.append(rows.Name) # column name
# or use
rows[0] # column index
Upvotes: 1