Exemple #1
0
    
def introduce():
    print "I just introduce myself."
       
# Every method inside a class receive a ‘self’ parameter because the ‘self’ will be passed into
# a reference to it corresponding instance of its class. In the inner virtual machine, the ‘binding’ will
# save you lots of time and keep you from many troubles.

# Function introduce() is defined without self as parameter because it is not a instance method nor class method.

# Reflection in Actions

from Reflect import reflect
from Reflect import introduce
if __name__ == '__main__':
    ref = reflect()
    
    print ref.__class__
    print ref.__dict__
    print ref.__doc__
    print ref.__sizeof__()
    
    print ref.__getattribute__('name')
    
    ref.__setattr__('name', 'Stranger')
    print ref.name
    
    introduce()
    ref.intro = introduce;
    ref.intro()
    
Exemple #2
0
from Reflect import reflect
from Reflect import welcome
if __name__ == '__main__':
    i = reflect()
    
    print i.__class__                         #1
    print i.__dict__                          #2
    print i.__doc__                           #3
    print i.__sizeof__()                      #4
    
    print i.__getattribute__('firstname')     #5
    i.__setattr__('firstname', 'Antoine')
    i.__setattr__('surname', 'Marchal')
    print i.firstname                         #6
    
    welcome()                                 #7
    i.hello = welcome;
    i.hello()                                 #8
    
    i.message()                               #9
    i.message = welcome
    i.message()                               #10