December 7th, 2012, 10:28 AM
Mysql-python writes unicode strings to the database
Using mysql-python, I receive unicode strings from the database. How can I encode them using utf-8 before inserting into the database. The problem is with the current setup, the tables contain unicode strings i.e. prefixed with u'' when I execute a Python file that reads and writes to the database. Any suggestions ?
December 7th, 2012, 12:33 PM
Is the problem just that you have Unicode strings you want to encode to bytestrings?
If so, there is an encode() method for that.
December 7th, 2012, 01:11 PM
What will you do when you have hundreds of python files that read from the db and perform insert operations? I cannot change all these files to encode the Unicode string before insert. Also, I'm not sure how would you encode a list returned in Unicode. Iterating and encoding each item in the list is obviously not the way to do it.
Thanks for your response anyway.