no struct.pack for unicode strings?
Martin v. Loewis
martin at v.loewis.de
Fri Oct 18 04:30:54 EDT 2002
Radovan Garabik <spam at melkor.dnp.fmph.uniba.sk> writes:
> it should pack them as raw Py_UNICODE data. At least that is what
> I'd need
It happens that this is probably not what most people would expect:
Instead, they would expect to get an array of wchar_t (which may or
may not be the same thing as Py_UNICODE): why would any C API know
what Py_UNICODE is?
> This is exactly what I am trying to avoid, since I need to quickly loop
> over the strings (it is a dictionary index) written in the file - hence
> the C extension module.
> I am afraid that using PyUnicode_DecodeUTF8 (or anything that creates a
> PyObject) would impose a big speed penalty.
Did you actually measure this? I very much doubt you can demonstrate
any speed penalty.
In any case, to pack this as Py_UNICODE, you need to
.encode("unicode-internal") your string, then just add it to whatever
else you are packing.
Regards,
Martin
More information about the Python-list
mailing list