How to marshal objects to readable files?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Sep 14 17:03:55 EDT 2008


En Sun, 14 Sep 2008 15:09:52 -0300, Aaron "Castironpi" Brady  
<castironpi at gmail.com> escribió:

> On Sep 14, 10:28 am, nielinjie <nielin... at gmail.com> wrote:
>> Hi list:
>> I just want to marshal objects (instance of custom classes)to a human
>> *READABEL *file/string, and also, I want unmarshal it back. in xml
>> format or any other format.
>> Any advice? Which lib should I use?
>
> The PyYAML package produces the following (continued):
>
>>>> print yaml.dump( a )
> &id001 !!python/object:__main__.A
> b: 0
> c: abc
> d: !!python/object:__main__.A
>   d: efg
>   e: 1.2
>   parent: *id001
>

JSON is another format, much simpler and probably more suited for human  
reading. But it is somewhat limited on what it can represent. There are a  
few Python implementations, maybe the most used is simplejson, which comes  
bundled with Python 2.6 as the json module.

-- 
Gabriel Genellina




More information about the Python-list mailing list