python - How do I use pywintypes.Unicode()? -


how use pywintypes.unicode in python 3.3.5?

import pywintypes pywintypes.unicode("s") 

this produces error:

traceback (most recent call last):   file "<pyshell#10>", line 1, in <module>     pywintypes.unicode("s") typeerror: must impossible<bad format char>, not str 

i've seen other code uses look same me, wrong here?

tl;dr: it's bug affecting python 3, , don't need pywintypes.unicode(text) in python 3. use text directly if need string , bytes(text, encoding) if need them bytes.

the error

typeerror: must impossible<bad format char>, not str 

hints @ bad format char in c++ source, t#, impossible (unknown).

thanks eryksun's comments , looking @ documentation pages of pyarg_parsetuple() python 2 , python 3, becomes clear bug in win32/src/pywintypesmodule.cpp.

pywintypes_export pyobject *pywin_newunicode(pyobject *self, pyobject *args) {     char *string;     int slen;     if (!pyarg_parsetuple(args, "t#", &string, &slen)) // <-- bug: python 2 format char         return null;     return pyunicode_decodembcs(string, slen, null); } 

t# exists python 2, python 3 should s*, , according eryksun, mbcs-decoding unnecessary python handles unicode strings automatically.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -