n | def fcounter(class_name, *args): | n | def fcounter(object, *args): |
| cm = [field for field in dir(class_name) if | | method_list = [func for func in dir(object) if callable( |
| callable(getattr(class_name, field)) and not field.startswith('_')] | | getattr(object, func)) and not func.startswith('_')] |
| | | fields_list = [func for func in dir(object) if not callable( |
| | | getattr(object, func)) and not func.startswith('_')] |
| | | class_instance = object(*args) |
| | | instance_method_list = [ |
| | | func for func in dir(class_instance) if callable( |
| | | getattr( |
| | | class_instance, |
| | | func)) and not func.startswith('_') and func not in method_list] |
| | | instance_fields_list = [ |
| cf = [field for field in dir(class_name) if not callable( | | func for func in dir(class_instance) if not callable( |
| getattr(class_name, field)) and not field.startswith('_')] | | getattr( |
| | | class_instance, |
| instance = class_name(*args) | | func)) and not func.startswith('_') and func not in fields_list] |
| | | return method_list, fields_list, instance_method_list, instance_fields_list |
| om = [field for field in dir(instance) if | | |
| callable(getattr(instance, field)) and | | |
| not field.startswith('_') and | | |
| field not in cm] | | |
| | | |
| of = [field for field in dir(instance) if | | |
| not callable(getattr(instance, field)) and | | |
| not field.startswith('_') and | | |
| field not in cf] | | |
| | | |
| return cm, cf, om, of | | |
| | | |
| | | |
| # class C: | | # class C: |
| # x, y, z = 1, 3, 5 | | # x, y, z = 1, 3, 5 |
n | | n | # |
| # def X(self): return self.x | | # def X(self): return self.x |
| # def Y(self): return self.y | | # def Y(self): return self.y |
n | | n | # |
| # def __init__(self, dx, dy, dz): | | # def __init__(self, dx, dy, dz): |
| # self.x = dx | | # self.x = dx |
| # self.Y = dy | | # self.Y = dy |
| # self.Z = dz | | # self.Z = dz |
t | | t | # |
| | | |
| # cm, cf, om, of = fcounter(C, 6, 7, 8) | | # cm, cf, om, of = fcounter(C, 6, 7, 8) |
| # print("Class: methods", *cm) | | # print("Class: methods", *cm) |
| # print("Class: fields", *cf) | | # print("Class: fields", *cf) |
| # print("Object: methods", *om) | | # print("Object: methods", *om) |
| # print("Object: fields", *of) | | # print("Object: fields", *of) |
| | | |