Inspect
  • get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects
    1. class Vehicle(object):
    2. """ Vehicle class """
    3.  
    4. count = 0; # class attribute
    5.  
    6. def __init__(self, brand):
    7. self.__brand = brand
    8. Vehicle.count += 1
    9.  
    10. @property
    11. def brand(self):
    12. return self.__brand
    13.  
    14. @brand.setter
    15. def brand(self, b):
    16. self.__brand = b
    17.  
    18. @brand.deleter
    19. def brand(self):
    20. del self.__brand
    21.  
    22. def __str__(self):
    23. return "Brand: %s" % self.__brand
    24.  
    25. def __getattr__(self, attr):
    26. return "~"
    27.  
    28. def __del__(self):
    29. Vehicle.count -= 1
    30. print("Delete %s, %d vehicles left ..." % (self.__brand, Vehicle.count))
    31.  
    32. def main():
    33. v1 = Vehicle("Lincoln")
    34.  
    35. import inspect
    36. from pprint import pprint
    37.  
    38. m = inspect.getmembers(v1, inspect.ismethod)
    39. pprint(m)
    40.  
    41. if __name__ == '__main__':
    42. main()
    Reference
  • Python STL Library