[IronPython] Portable use of pickle.dumps()

Robert Smallshire robert at smallshire.org.uk
Fri May 29 08:38:07 CEST 2009


I'm trying to get some commercial code for a simple object database we have
written for Python 2.6 to work with IronPython 2.6. In Python 2.6 the return
type of pickle.dumps() is str, which is of course a byte string.  In
IronPython 2.6 it is also str, which is of course a unicode string.  This
'compatibility' is fine until I put those strings into a database, at which
point my interoperability between CPython and IronPython goes off the rails.

I notice that in Python 3.0 the return type of pickle.dumps() is now
'bytes', which is much better.  I don't imagine you're about to change the
return type in IronPython 2.x to bytes even though that would arguably be
the right thing to do.  I intend to provide a compatibility wrapper around
pickle that returns a bytes instance on CPython 2.6, IronPython 2.6 and
Python 3.0. 

What is the preferred way to transform my unicode 'str' in IronPython into a
'bytes' instance in IronPython that will be byte-compatible with what I'm
getting from CPython?

Many thanks,


Robert Smallshire
from home on behalf of
Roxar Software Solutions
Currently in Norway (UTC +1 hours) 

More information about the Ironpython-users mailing list