[IronPython] Pickle-Serialization integration

J. Merrill jvm_cop at spamcop.net
Thu Feb 8 17:07:51 CET 2007


You could implement ISerializable on Python objects by pickling the object (using the regular Python pickle mechanism) and using the resulting string as the serialized value (perhaps with some kind of sanity-test header and/or trailer).  Unserializing would then require unpickling the serialized string.

At 12:52 AM 2/7/2007, Sanghyeon Seo wrote
>Python has pickle, and .NET has System.Runtime.Serialization, and they
>do roughly the same thing.
>
>So one should be able to pickle any .NET objects that is serializable.
>
>As Python's pickle has a mechanism to register custom hooks, I wrote
>hooks to delegate pickling of .NET objects to
>System.Runtime.Serialization. It works fine!
>
>This is how it looks like:
>
>from System import DateTime
>import pickle
>import fepy.pickle
>fepy.pickle.register(DateTime)
>
>obj = DateTime.Now
>string = pickle.dumps(obj)
>newobj = pickle.loads(string)
>assert obj == newobj
>
>Does it make to sense to do the reverse? That is, making picklable
>Python objects serializable by, I guess, implementing ISerializable? I
>have no idea how to go about that. Any suggestions welcome.
>
>-- 
>Seo Sanghyeon


J. Merrill / Analytical Software Corp





More information about the Ironpython-users mailing list