[PonyORM-list] Class does not return dict

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Mon May 5 04:32:14 UTC 2014


Hi,

Pony doesn't use __dict__, but you can construct it yourself the next way:

1) Iterate over object attributes listed in obj._attrs_
2) Optionally, filter out attributes which you don't want to see inside
dict, such as collections
3) As each attribute implements descriptor protocol, you can call
attr.__get__(obj) to get value of this attribute

The code will look like this:

def make_dict(obj):
    result = {}
    for attr in obj._attrs_:
        if not attr.is_collection:
            result[attr.name] = attr.__get__(obj)
    return result




On Fri, May 2, 2014 at 4:02 PM, Руслан Загирович <giggles at mail.ru> wrote:

> Hello
> I have a 'Car' class. I want it to return dict object lik this:
> Car[1].__dict__
> but it returns empty list: {}
>
>
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20140505/30039f09/attachment.html>


More information about the ponyorm-list mailing list