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
more....defs..etc.
CallAmount = property(GetCallAmount,None,None,None)
CallCurrency = property(GetCallCurrency, None, None, None)
more....properies..etc.
For debugging purposes, I would like to traverse the class listing out
all the properties. 9 1251
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
more....defs..etc.
CallAmount = property(GetCallAmount,None,None,None)
CallCurrency = property(GetCallCurrency, None, None, None)
more....properies..etc.
For debugging purposes, I would like to traverse the class listing out
all the properties.
for attr in dir( yourclass ):
if repr( yourclass.__dict__[ attr ] ).startswith( '<property' ):
print 'This looks like a property although can be something
else too: ' + attr
:)
On 2007-01-18, EdG <ed*******@yahoo.comwrote:
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 attr
--
Neil Cerutti
--
Posted via a free Usenet account from http://www.teranews.com
Thanks.
Neil Cerutti wrote:
On 2007-01-18, EdG <ed*******@yahoo.comwrote:
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 attr
--
Neil Cerutti
--
Posted via a free Usenet account from http://www.teranews.com
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
more....defs..etc.
CallAmount = property(GetCallAmount,None,None,None)
CallCurrency = property(GetCallCurrency, None, None, None)
more....properies..etc.
For debugging purposes, I would like to traverse the class listing out
all the properties.
for attr in dir( yourclass ):
if repr( yourclass.__dict__[ attr ] ).startswith( '<property' ):
print 'This looks like a property although can be something
else too: ' + attr
:)
EdG a écrit :
I'm using Python version 2.4 and I created a class with some properties
like:
def GetCallAmount(self):
return somedata
<mode="pep08">
The recommended naming convention is all_lower,ie:
def get_call_amount(self):
</mode>
And FWIW, there are idioms to avoid polluting the class namespace, like:
class Account(object):
@apply
def amount():
def fget(self):
return something
def fset(self, value):
do_something_with(value)
return property(**locals())
For debugging purposes, I would like to traverse the class listing out
all the properties.
cf Neil's answer.
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 <ed*******@yahoo.comwrote:
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 attr
--
Neil Cerutti
--
Posted via a free Usenet account from http://www.teranews.com
EdG a écrit :
(top-post corrected)
>
Neil Cerutti wrote:
>>On 2007-01-18, EdG <ed*******@yahoo.comwrote:
>>>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 attr
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)
Then you need to have the instance...
def list_properties(cls):
return [
name for name in dir(cls)
if isinstance(getattr(cls, name), property)
]
def print_properties(obj):
for name in list_properties(obj.__class__):
print "%s : %s" % (name, str(getattr(obj, name)))
That works perfectly thank you.
Bruno Desthuilliers wrote:
EdG a écrit :
(top-post corrected)
Neil Cerutti wrote:
>On 2007-01-18, EdG <ed*******@yahoo.comwrote:
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 attr
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)
Then you need to have the instance...
def list_properties(cls):
return [
name for name in dir(cls)
if isinstance(getattr(cls, name), property)
]
def print_properties(obj):
for name in list_properties(obj.__class__):
print "%s : %s" % (name, str(getattr(obj, name)))
On Thu, 18 Jan 2007 18:03:41 +0000, Neil Cerutti wrote:
On 2007-01-18, EdG <ed*******@yahoo.comwrote:
>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 attr
Funny. The first thing that came to my mind was, "Thank you for sharing.
Did you have a question?"
*wink*
--
Steven. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: w.p. |
last post by:
Hello!
I want change default tab traversing in my app. But i don't know how to do it :(
Belowe i include simple example - i want change default...
|
by: Plamen Valtchev |
last post by:
This is my problem:
From JavaScript I want to find the list of all defined/loaded
JavaScript functions/objects/names within the current scope...
|
by: X |
last post by:
I cannot figure this one out. I would like to traverse through and
elements styles (not class) and get a list of all properties using
javascript...
|
by: alfred |
last post by:
Hi
my question is on traversing a tree with DOM. how would I be able to
traverse 2 trees at the same time. I have 2 XML documents, with similar...
|
by: nmosafi |
last post by:
I have a datagrid that I am binding to a custom collection, and I am
having problems with data binding in an ASP.NET datagrid (1.1
framework).
...
|
by: plmanikandan |
last post by:
Hi,
I am new to link list programming.I need to traverse from the end of
link list.Is there any way to find the end of link list without...
|
by: fig000 |
last post by:
Hi,
I'm pretty new to the new dot.net. I've been able to quickly set up
a grid view with page, etc. The gridview is connected to a drop down...
|
by: asit |
last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can
stack be traversed ??
|
by: somcool |
last post by:
I am facing an error while traversing a query in MS Access
Details - When I click a button, a form which has the query opens up. There are certain...
|
by: tammygombez |
last post by:
Hey everyone!
I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: CD Tom |
last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
| |