#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    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 ?

    Thanks
    Ravi
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    4
    Is the problem just that you have Unicode strings you want to encode to bytestrings?

    If so, there is an encode() method for that.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo