+import pymysql, json, pprint
+from sqlalchemy import text
+
+def test():
+ db_connection = pymysql.connect(
+ user= 'insang',
+ passwd= 'Whtkd530823#',
+ host= 'insang.duckdns.org',
+ db= 'weddingcard',
+ charset= 'utf8'
+ )
+ cursor= db_connection.cursor(pymysql.cursors.DictCursor)
+ cursor.execute("select * from guestbook")
+ # result= json.dumps(cursor.fetchall(), ensure_ascii=True)
+ result= cursor.fetchall()
+ return MyPrettyPrinter().pprint(result)
+
+
+class MyPrettyPrinter(pprint.PrettyPrinter):
+ def format(self, _object, context, maxlevels, level):
+ if isinstance(_object, str):
+ return "'%s'" % _object.encode('utf8'), True, False
+ elif isinstance(_object, str):
+ _object = str(_object, 'utf8')
+ return "'%s'" % _object.encode('utf8'), True, False
+ return pprint.PrettyPrinter.format(self, _object, context, maxlevels, level)
\ No newline at end of file