I'm new to python, I have a trouble reading data from mysql. Here in mysql, my table stores destination:
|id | Destination| |1 |Hà Nội | |2 |Hồ Chí Minh | ... but when I read it from python its return this: ' u\'H\xe0 N\u1ed9i\'' for Hà Nội. Is there any way to convert it back to original string: 'Hà Nội' here is my code to open connection and select data:
def __init__(self): self.mySQLConnection = mysql.connector.connect(user='root', password='', host='localhost',database='traveltrend',charset='utf8',use_unicode=True) self.cursor = self.mySQLConnection.cursor(buffered=True) def getDest(self): self.cursor.execute("SELECT ID, ThanhPho FROM diadiem ") row = self.cursor.fetchone() listDest={} while row is not None: request = str(row) request = request.strip('()') request = request.split(',') encoding = "utf-8" on_error = "replace" place= request[1].encode(encoding,on_error)
destination(IDint(11) NOT NULL,ThanhPhovarchar(50) CHARACTER SET utf8 COLLATE utf8_vietnamese_ci NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_vietnamese_ci; @arun