[Zope] Examining Properties of Returned Object
Dragos Chirila
d.chirila@bucarest.finsiel.ro
Tue, 20 May 2003 10:42:42 +0300
Hi
In O'Reilly Python Cookbook is an article "Getting all members of a class
hierarchy". Here is the code:
def all_members(aClass):
try:
#try getting all relevant classes in method-resolution order
mro = list(aClass.__mro__)
except AttributeError:
#if a class has no __mro__, then it's a classic class
def getmro(aClass, recurse):
mro = [aClass]
for base in aClass.__bases__: mro.extend(recurse(base, recurse))
return mro
mro = getmro(aClass, getmro)
mro.reverse()
memebers = {}
for someClass in mro: members.update(vars(someClass))
return members
"The all_members function creates a dictionary that includes seach
member(such as methods and data attributes) of a class with the name as the
key and the class attribute value as the corresponding value."
If you have the book take a look 'cause there is more stuff.
i hope this will help
dragos
----- Original Message -----
From: "Samir Mishra" <SamirMishra@cbuae.gov.ae>
Cc: <zope@zope.org>
Sent: Tuesday, May 20, 2003 10:17 AM
Subject: RE: [Zope] Examining Properties of Returned Object
> Thanks Troy. I wasn't clear in my earlier email...
>
> I know how to get at the attribute/method of an object if I know what it's
> name is. By using someobj.attributename or someobj.methodname() (or using
> 'getattr(....)'). But how do I enumerate all attributes & methods
associated
> with an object when I don't know the structure of the object (i.e., as if
I
> was exploring the object in a debugger)?
>
> I've been using Dieter Maurer's DocFinderEverywhere extensively to get
info
> on generic objects returned by Zope (thanks Dieter, very helpful product,
> especially for beginners), but obviously it has it's limitations.
>
> Thanks again.
> SM.
>
> -----Original Message-----
> From: Troy Farrell [mailto:troy@entheossoft.com]
> Sent: Tuesday, May 20, 2003 08:40
> To: Samir Mishra
> Cc: 'zope@zope.org'
> Subject: Re: [Zope] Examining Properties of Returned Object
>
>
> What is calling your python script? Is it TAL(ES), DTML, another python
> script, a zope product or an external method? Unfortunately, each of
> these has some slightly different methods... Did you try
>
> obj.myattribute
>
> or
>
> getattr(obj, myattribute)
>
> or (in TAL)
>
> obj/myattribute
>
> Thanks.
> Troy
>
> Samir Mishra wrote:
> > Hello all,
> >
> > I'm sure there's a way, just can't figure it out...
> >
> > I have a python script returning an object. The result set I'm actually
> > interested in is wrapped somewhere within this object.
> >
> > My question: how can I examine the properties/methods of an object
> returned
> > by Python?
> >
> > Thanks in advance.
> >
> > Regards,
> > Samir
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>