Quickest marshal.loads from unicode?

Giles Brown giles_brown at hotmail.com
Fri Feb 21 04:18:40 EST 2003


Problem
-------
How can the I take the result of a marshal.dumps call and decode
(encode?) it
into a unicode string so that the conversion back to a marshal.loads
compatible string is as quick as possible?

Context
-------

I have an application that uses a large number of Python code
fragments
that are expressions. I have to pre-process these fragments (using the
compiler module).  For the number of expressions I have this can take
quite a long time.
I'd like to pre-compile the expressions and store them in an MS Access
database (because the rest of the application uses an MS Access
database.) It looks like an MS Access Memo field is most suited, but
the win32com wrapper for the memo field takes and gives a unicode
string.  I don't care if the pre-compilation is a bit time consuming,
but the decoding + marshal.loads needs to be nippy.

Already Tried
-------------
I have googled for guidance on how to fit a binary data square peg
into a unicode string round hole.
Found swathes of python dev discussings on uses of
'raw-unicode-escape' vs 'utf-8' but couldn't find an answer that I
understood as definitive.

I have also tried doing a base64 encoding before I do a straight
forward
".decode('ascii')", but unfortunately because this in a performance
sensitive part of the app (i.e. its done lots of times at start-up) it
seems to slow down the performance a fair bit.

Tips and suggestions appreciated,
Giles




More information about the Python-list mailing list