Display all properties with reflection
sccs cscs
zorg724 at yahoo.fr
Sat Oct 20 05:03:55 EDT 2007
Hello,
I like create a methode that display all the properties of an instance of classe with their value.
I try the following code: see def __str__ (self) methode.
But it displays only the instance attributes values not the properties and their value.
In pseudo-code:
For Each Properties :
print property_name, property_value
It is possible ? Where is the collection of properties into the Python Object Metamodele?
Thank you.
Zorgi
class PhysicalObject(Subject):
"""
Base class for physical Object
They inherit from Subject whose contract are:
def attach(self, observer)
def detach(self, observer)
def notify(self, modifier = None)
"""
def __init__(self, World, Space, ThePhysicalProperties):
"""
"""
#Initialize Subject-Observers mecanism
Subject.__init__(self)
self.__name = None
....
...
def __str__ (self):
"""
Return a string that describe the value of all attributes for the instance
"""
result = None
msgList = ["%s --->%s"%(str(attribute), str(value)) for (attribute, value) in self.__dict__.items()]
msgList.sort()
result = "\n\n%s instance :" % (self.__class__.__name__)
result += "\n".join (msgList)
return result
Name = property(fget = __getName, fset = __setName)
Position = property(fget = __getPosition, fset = __setPosition)
LinearVelocity = property(fget = __getLinearVelocity, fset = __setLinearVelocity)
AngularVelocity = property(fget = __getAngularVelocity, fset = __setAngularVelocity)
RotationMatrice = property(fget = __getRotationMatrice, fset = __setRotationMatrice)
Masse = property(fget = __getMass, fset = __setMass)
GravityMode = property(fget = __getGravityMode, fset = __setGravityMode)
---------------------------------
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071020/148bbe7f/attachment.html>
More information about the Python-list
mailing list