I'm very new to Python and MySQL, I have dumped a file in database using python, on executing a query Select * from table_name
I am getting the result in Unicode format i.e
(1, u'John',u'smith')
(2, u'Markus',u'Doe')
(3, u'Andrew',u'smith')
but, I required in this format
(1, 'John','smith')
(2, 'Markus','Doe')
(3, 'Andrew','smith')
The file using encoding="utf-8" format Because of this unicode format, I'm unable to perform any insertion based on foreign keys
python code for this problem:
with codecs.open("input.txt", "r", encoding="utf-8") as f:
for num,line in enumerate(f,1):
try:
words=line.split('\t')
list =[]
for word in words:
list.append(word.encode("utf-8"))
args = (list[0],list[0])
cursor.execute(query,args)
f.close()
cursor.execute("Select * from table_name")
rows = cursor.fetchall()
print('Total Row(s):', cursor.rowcount)
for row in rows:
print [type(word) for word in row]
conn.commit()
conn.close()
Please help me, thank you in advance.