Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode string with hex characters in python 2

I have a hex string and i want to convert it utf8 to insert mysql. (my database is utf8)

hex_string = 'kitap ara\xfet\xfdrmas\xfd'
...
result = 'kitap araştırması'

How can I do that?

like image 532
user260223 Avatar asked Jun 15 '10 14:06

user260223


1 Answers

Try(Python 3.x):

import codecs
codecs.decode("707974686f6e2d666f72756d2e696f", "hex").decode('utf-8')

From here.

like image 143
gangmax Avatar answered Sep 30 '22 15:09

gangmax