mysql - How to compare non-English(Chinese) Characters in python program? -


in 1 of python program(python 2.7), need process chinese characters:

  1. i have file a.txt, has 2 columns: "name" , "score", "name" column can valued chinese strings, , score int number values between 1 , 10. a.txt encoded in gbk, chinese character encoding.

  2. i insert every row of a.txt mysql table tb_name_score, has 3 columns: id, name, score, , name column's encoding latin1_swedish_ci

  3. now, have file names b.txt, has 2 columns too, "name" , "score", , need update tb_name_score's score column according b.txt. b.txt encoded in gbk

  4. so, traverse b.txt, read line , use it's "name" value compare records in tb_name_score.name, if equal, update tb_name_score.score. however, although "name" column of line in b.txt same chinese string value in tb_name_score.name, "=" returns false, can't update table. can help? thanks!

hope helps:

python 2.7.3 (default, apr 10 2013, 06:20:15)  [gcc 4.6.3] on linux2 type "help", "copyright", "credits" or "license" more information. >>> a=u'后者' >>> b='后者' >>> type(a) <type 'unicode'> >>> type(b) <type 'str'> >>> a==b __main__:1: unicodewarning: unicode equal comparison failed convert both arguments unicode - interpreting them being unequal false >>> b '\xe5\x90\x8e\xe8\x80\x85' >>> u'\u540e\u8005' >>> b.decode('utf8') u'\u540e\u8005' >>> a.encode('utf8') '\xe5\x90\x8e\xe8\x80\x85' >>>  

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -