On Tue, Jul 12, 2011 at 6:25 PM, Lukich <luk...@gmail.com> wrote:

> Hi.  I have just started diving into Django and this question came up
> - is there a way for me to examine all the attribute values of an
> object?  In Rails there's such a thing as debug statement which spits
> out all the details about the object.  From what I have seen so far in
> Django, I can either do a __unicode__() trick, but it forces me to
> specify which attribute to show.  I also read about dir() and
> __dict__, but they show me sets of attributes without their values. Is
> there something I'm missing? Thank you!
>

Ah, yeah I know what you mean. You want the PHP equivalent of "vardump".

I'm not aware of anything that does it, but it would be easy to make, by
extending on dir:

def inspectobj(obj):
    return dict(map(lambda x: (x, getattr(obj, x)), dir(obj)))

pprint.pprint(inspectobj(django.db))
pprint.pprint(inspectobj(str))
pprint.pprint(inspectobj(django))

This is very very very basic, and you'd need to add all sorts of
conditionals in there to make it extract the information you want in a
proper, recursive fashion (and telling it how to deal with unbound methods
etc), but it's a start.

Enjoy :)

Cal



> Luka
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to