I have a column of type NVARCHAR in my database. I cannot convert the contents of this column to a regular string in my code. (I am using pyodbc to connect to the database).
# This unicode string is returned by the database >>> my_string = u'\u4157\u4347\u6e65\u6574\u2d72\u3430\u3931\u3530\u3731\u3539\u3533\u3631\u3630\u3530\u3330\u322d\u3130\u3036\u3036\u3135\u3432\u3538\u2d37\u3134\u3039\u352d'
The closest I left is its encoding to utf-16 like:
>>> my_string.encode('utf-16') '\xff\xfeWAGCenter-04190517953516060503-20160605124857-4190-5' >>> print my_string.encode('utf-16') WAGCenter-04190517953516060503-20160605124857-4190-5
But the actual value that I need is according to the store of values in the database:
WAGCenter-04190517953516060503-20160605124857-4190-51
I tried with encoding utf-8 , utf-16 , ascii , utf-32 , but nothing worked.
Does anyone have an idea regarding what I don't see? And how to get the desired result from my_string .
Change When converting it to utf-16-le I can remove unnecessary characters from the beginning, but still one character is missing from the end
>>> print t.encode('utf-16-le') WAGCenter-04190517953516060503-20160605124857-4190-5
When trying to use some other columns it works. What could be causing this intermittent problem?
source share