标签:back icm att iba rac number log line static
# coding:utf-8 import traceback class A(object): __static_field = ‘A_private static field‘ public_static_field = ‘A_public_static_field‘ start_urls = "A_class_start_urls" _one_line = "A_one_line" def __init__(self): (filename, line_number, function_name, text) = traceback.extract_stack()[-2] self.name = text[:text.find(‘=‘)].strip()
self.start_urls = "object_start_urls" if not hasattr(self, "_one_line"): # 类属性中有,也算类实例有 self._one_line = ‘123‘ def __str__(self): return self.name def A_comm_func(self): return "A_comm_func" @classmethod def A_classmethod(cls): return "A_classmethod" @staticmethod def A_staticmethod(): return "A_staticmethod" def repeat(self): return "A_repeat" def ree(self): return self.__re() def __re(self): return "A__re" class B(A): B_public_field = "B_public_field" __B_pri_field = ‘B_pri_field‘ _B_one_line = ‘B_one_line‘ public_static_field = "B_public_static_field" _one_line = "B_one_line" def repeat(self): return "B_repeat" def B_comm_func(self): return "B_comm_func" @classmethod def B_classmethod(cls): return "B_classmethod" @staticmethod def B_staticmethod(): return ‘B_staticmethod‘ a = A() b = B() print "--------------A.dict-----------" print A.__dict__ print "--------------B.dict-----------" print B.__dict__ print "------------ a.__dict__ -----------" print a.__dict__ print "--------- b.dict -----------" print b.__dict__ # print b.A_classmethod() print B.A_classmethod() print A._one_line print a._one_line print b._one_line # 先从自己__dict__找,在去类找,再到类的父类找 print B._one_line # 先从自己找,再去父类找 b._one_line = ‘luanqibazao‘ print b._one_line
标签:back icm att iba rac number log line static
原文地址:http://www.cnblogs.com/jijizhazha/p/7071373.html