Re: Traversing the properties of a Class

2007-01-19 Thread Steven D'Aprano
On Thu, 18 Jan 2007 18:03:41 +, Neil Cerutti wrote: > On 2007-01-18, EdG <[EMAIL PROTECTED]> wrote: >> For debugging purposes, I would like to traverse the class >> listing out all the properties. > > This is the first thing that came to mind. > > def show_properties(cls): > for attr in di

Re: Traversing the properties of a Class

2007-01-18 Thread EdG
That works perfectly thank you. Bruno Desthuilliers wrote: > EdG a écrit : > (top-post corrected) > > > > Neil Cerutti wrote: > > > >>On 2007-01-18, EdG <[EMAIL PROTECTED]> wrote: > >> > >>>For debugging purposes, I would like to traverse the class > >>>listing out all the properties. > >> > >>Thi

Re: Traversing the properties of a Class

2007-01-18 Thread Bruno Desthuilliers
EdG a écrit : (top-post corrected) > > Neil Cerutti wrote: > >>On 2007-01-18, EdG <[EMAIL PROTECTED]> wrote: >> >>>For debugging purposes, I would like to traverse the class >>>listing out all the properties. >> >>This is the first thing that came to mind. >> >>def show_properties(cls): >> for a

Re: Traversing the properties of a Class

2007-01-18 Thread EdG
This works great. I have one more question. Now that I have the name of the property, how do I get it's value? I want to print '%s = %s' % (attr,theattributesvalue) Thanks. Neil Cerutti wrote: > On 2007-01-18, EdG <[EMAIL PROTECTED]> wrote: > > For debugging purposes, I would like to traverse

Re: Traversing the properties of a Class

2007-01-18 Thread Bruno Desthuilliers
EdG a écrit : > I'm using Python version 2.4 and I created a class with some properties > like: > > def GetCallAmount(self): > return somedata The recommended naming convention is all_lower,ie: def get_call_amount(self): And FWIW, there are idioms to avoid polluting the class namespace

Re: Traversing the properties of a Class

2007-01-18 Thread EdG
Thanks. Daniel Nogradi wrote: > > I'm using Python version 2.4 and I created a class with some properties > > like: > > > > def GetCallAmount(self): > > return somedata > > > > def GetCallCurrency(self): > > return somemoredata > > > > moredefs..etc. > > > > CallAmount =

Re: Traversing the properties of a Class

2007-01-18 Thread EdG
Thanks. Neil Cerutti wrote: > On 2007-01-18, EdG <[EMAIL PROTECTED]> wrote: > > For debugging purposes, I would like to traverse the class > > listing out all the properties. > > This is the first thing that came to mind. > > def show_properties(cls): > for attr in dir(cls): > if isinstance(

Re: Traversing the properties of a Class

2007-01-18 Thread Neil Cerutti
On 2007-01-18, EdG <[EMAIL PROTECTED]> wrote: > For debugging purposes, I would like to traverse the class > listing out all the properties. This is the first thing that came to mind. def show_properties(cls): for attr in dir(cls): if isinstance(getattr(cls, attr), property): print at

Re: Traversing the properties of a Class

2007-01-18 Thread Daniel Nogradi
> I'm using Python version 2.4 and I created a class with some properties > like: > > def GetCallAmount(self): > return somedata > > def GetCallCurrency(self): > return somemoredata > > moredefs..etc. > > CallAmount = property(GetCallAmount,None,None,None) > CallCurrency

Traversing the properties of a Class

2007-01-18 Thread EdG
I'm using Python version 2.4 and I created a class with some properties like: def GetCallAmount(self): return somedata def GetCallCurrency(self): return somemoredata moredefs..etc. CallAmount = property(GetCallAmount,None,None,None) CallCurrency = property(Get