Perl Dictionary Convert

faulkner faulkner612 at comcast.net
Wed Jul 5 16:42:38 EDT 2006


data.replace('=', ':').replace(';', ',')
then eval in a namespace object whose __getitem__ method returns its
argument unchanged.


class not_str(str):    # take care of that IPF.Contact
    def __getattr__(self, attr):return self + '.' + attr

class not_dict(dict):
    def __getitem__(self, name):return not_str(name)

eval(data.replace('=',':').replace(';', ','), not_dict())



Tom Grove wrote:
> I have a server program that I am writing an interface to and it returns
> data in a perl dictionary.  Is there a nice way to convert this to
> something useful in Python?
>
> Here is some sample data:
>
> 200 data follow
> {
>   Calendar =  {
>     Access =  { anyone = lr;};
>     Class =  IPF.Appointment;
>     Messages =  0;
>     Size =  0;
>     UIDNext =  1;
>     UIDValidity =  287898056;
>     Unseen =  0;
>   };
>   Contacts =  {
>     Class =  IPF.Contact;
>     Messages =  0;
>     Size =  0;
>     UIDNext =  1;
>     UIDValidity =  287898056;
>     Unseen =  0;
>   };
> }
> 
> -Tom




More information about the Python-list mailing list