Display all properties with reflection

2007-10-20 Thread sccs cscs
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 -- 
http://mail.python.org/mailman/listinfo/python-list

Get the instance name from a list by Reflection

2007-10-20 Thread sccs cscs
Hello,
I cannot find into documentation how to get the instance name. I found the 
attributes __dict__,__class__ ,__bases__ __name__ ,
but if i have the code:

class A :pass
a1 = A ()
a2 = A ()
aList = [a1,a2]
for elem in aList :
print elem.__instance_name__ ???

I expect to have "a1" "a2" ...
But it does not work ...
help please
Zorgi

 
-
 Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail -- 
http://mail.python.org/mailman/listinfo/python-list

Delete a instance passed by reference into a method

2007-12-03 Thread sccs cscs
Hello,
I am very surprising by the Python interpreter behavior : see code
I initialize a 'A' and a 'B', and i give a B instance reference to the  
instance A in 'm1' method. I can modify (IN/OUT mode)  the 'i' attribute  (  
aB.i = 10 ) , BUT I CANNOT DELETE "aB" into the fonction m1 ! the code " 
del aB " or " aB= None" has no effect. 'aB' still exists when m1() is finsihed! 
WHY ? How can i do that?
Thank you.
Zorgi


class A(object):
   def __init__(self):
pass
def m1 (self, aB ):
aB.i = 10
del aB
print "no more B"

class B(object):
def __init__(self,i):
self.i = i
def __del__(self):
print "delete B"

aA = A ()
aB = B ( i = 6)

unA.m1 (aB )
print str( aB .i )  #--->  Display 10, aB is not destroy !



 
-
 Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail -- 
http://mail.python.org/mailman/listinfo/python-list

Python UML Metamodel

2008-01-29 Thread sccs cscs
Hello,
I find an OPEN SOURCE tool  (http://bouml.free.fr/) that Recently generates 
Python code from UML model.

I like to model the Python language metamodel himself, with it, e.g  the model 
of the language: I need that to better understand the language constraint of  
the language.

for example, i like to model that :
-a  class "class" may inherit from 0..* class
-a class "class" is create from a class that is its "metaclass"
-a class  "class" has 0..n attributes and 0..n method
-a class "module" has 0..n class "class"

Does anyone know a document that describes it already, because I think it is 
complicated to find this information in the documentation of Python.
For example, can i say that:

-a class  "class" has 0..n properties ?
It seems that the Python metamodel is not perfect, because I do not find 
attribute which give me the property list with a code like:
"myPropertyList = myclass.properties"

- a class "method" can contains nested "method", but what is the way to get a 
list of internal methods, without use ? Can i just write:
"myNestedMethodList = method.nestedMethodList"


I think a metamodel Python would be welcome to complement the BNF 
(http://docs.python.org/ref/grammar.txt), so as to know fully understand the 
relationships between the various elements of language.

Thank you








   
-
 Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail -- 
http://mail.python.org/mailman/listinfo/python-list