Message from discussion
Inspecting objects
Received: by 10.100.245.10 with SMTP id s10mr78076anh.11.1310492452057;
Tue, 12 Jul 2011 10:40:52 -0700 (PDT)
X-BeenThere: django-users@googlegroups.com
Received: by 10.101.83.10 with SMTP id k10ls70763anl.4.gmail; Tue, 12 Jul 2011
10:39:09 -0700 (PDT)
Received: by 10.101.2.17 with SMTP id e17mr69061ani.15.1310492349382;
Tue, 12 Jul 2011 10:39:09 -0700 (PDT)
Received: by 10.101.2.17 with SMTP id e17mr69060ani.15.1310492349335;
Tue, 12 Jul 2011 10:39:09 -0700 (PDT)
Return-Path: <c...@foxwhisper.co.uk>
Received: from mail-gy0-f176.google.com (mail-gy0-f176.google.com [209.85.160.176])
by gmr-mx.google.com with ESMTPS id n19si13843395ani.0.2011.07.12.10.39.08
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 12 Jul 2011 10:39:08 -0700 (PDT)
Received-SPF: neutral (google.com: 209.85.160.176 is neither permitted nor denied by best guess record for domain of c...@foxwhisper.co.uk) client-ip=209.85.160.176;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 209.85.160.176 is neither permitted nor denied by best guess record for domain of c...@foxwhisper.co.uk) smtp.mail=...@foxwhisper.co.uk
Received: by gyb11 with SMTP id 11so2881341gyb.21
for <django-users@googlegroups.com>; Tue, 12 Jul 2011 10:39:08 -0700 (PDT)
Received: by 10.236.178.8 with SMTP id e8mr290481yhm.276.1310492347542;
Tue, 12 Jul 2011 10:39:07 -0700 (PDT)
Return-Path: <c...@foxwhisper.co.uk>
Received: from mail-yx0-f174.google.com (mail-yx0-f174.google.com [209.85.213.174])
by mx.google.com with ESMTPS id o47sm10272844yhn.30.2011.07.12.10.39.05
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 12 Jul 2011 10:39:07 -0700 (PDT)
Received: by yxi11 with SMTP id 11so2662683yxi.33
for <django-users@googlegroups.com>; Tue, 12 Jul 2011 10:39:05 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.151.84.2 with SMTP id m2mr387249ybl.42.1310492345450; Tue, 12
Jul 2011 10:39:05 -0700 (PDT)
Received: by 10.151.156.4 with HTTP; Tue, 12 Jul 2011 10:39:05 -0700 (PDT)
X-Originating-IP: [81.152.150.229]
In-Reply-To: <c8520d3c-2346-4ac9-a226-222016b48...@g3g2000prf.googlegroups.com>
References: <c8520d3c-2346-4ac9-a226-222016b48...@g3g2000prf.googlegroups.com>
Date: Tue, 12 Jul 2011 18:39:05 +0100
Message-ID: <CALvtuFSTtDKr6YBNDPcdoEwot=pqPPdVEv=rYZZH8hQM5Gt...@mail.gmail.com>
Subject: Re: Inspecting objects
From: Cal Leeming <c...@foxwhisper.co.uk>
To: django-users@googlegroups.com
Content-Type: multipart/alternative; boundary=000e0cd59c72bb40d004a7e2c694
--000e0cd59c72bb40d004a7e2c694
Content-Type: text/plain; charset=ISO-8859-1
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+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
--000e0cd59c72bb40d004a7e2c694
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br><div class=3D"gmail_quote">On Tue, Jul 12, 2011 at 6:25 PM, Lukich =
<span dir=3D"ltr"><<a href=3D"mailto:luk...@gmail.com">luk...@gmail.com<=
/a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi. =A0I have just started diving into Django and this question came up<br>
- is there a way for me to examine all the attribute values of an<br>
object? =A0In Rails there's such a thing as debug statement which spits=
<br>
out all the details about the object. =A0From what I have seen so far in<br=
>
Django, I can either do a __unicode__() trick, but it forces me to<br>
specify which attribute to show. =A0I also read about dir() and<br>
__dict__, but they show me sets of attributes without their values. Is<br>
there something I'm missing? Thank you!<br></blockquote><div><br></div>=
<div>Ah, yeah I know what you mean. You want the PHP=A0equivalent=A0of &quo=
t;vardump".</div><div><br></div><div>I'm not aware of anything tha=
t does it, but it would be easy to make, by extending on dir:</div>
<div><br></div><div><div><div>def inspectobj(obj):</div><div>=A0 =A0 return=
dict(map(lambda x: (x, getattr(obj, x)), dir(obj)))</div><div><br></div><d=
iv>pprint.pprint(inspectobj(django.db))</div><div>pprint.pprint(inspectobj(=
str))</div>
<div>pprint.pprint(inspectobj(django))</div><div><br></div><div>This is ver=
y very very basic, and you'd need to add all sorts of conditionals in t=
here to make it extract the information you want in a proper, recursive fas=
hion (and telling it how to deal with unbound methods etc), but it's a =
start.</div>
<div><br></div><div>Enjoy :)</div><div><br></div><div>Cal</div></div></div>=
<div><br></div><div>=A0</div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Luka<br>
<font color=3D"#888888"><br>
--<br>
You received this message because you are subscribed to the Google Groups &=
quot;Django users" group.<br>
To post to this group, send email to <a href=3D"mailto:django-users@googleg=
roups.com">django-users@googlegroups.com</a>.<br>
To unsubscribe from this group, send email to <a href=3D"mailto:django-user=
s%2Bunsubscribe@googlegroups.com">django-users+unsubscribe@googlegroups.com=
</a>.<br>
For more options, visit this group at <a href=3D"http://groups.google.com/g=
roup/django-users?hl=3Den" target=3D"_blank">http://groups.google.com/group=
/django-users?hl=3Den</a>.<br>
<br>
</font></blockquote></div><br>
--000e0cd59c72bb40d004a7e2c694--