n | def fcounter(object, *args): | n | def fcounter(class_name, *args): |
| method_list = [func for func in dir(object) if callable( | | cm = [field for field in dir(class_name) if |
| | | callable(getattr(class_name, field)) and not field.startswith('_')] |
| | | |
| | | cf = [field for field in dir(class_name) if not callable( |
| getattr(object, func)) and not func.startswith('_')] | | getattr(class_name, field)) and not field.startswith('_')] |
| fields_list = [func for func in dir(object) if not callable( | | |
| getattr(object, func)) and not func.startswith('_')] | | instance = class_name(*args) |
| class_instance = object(*args) | | |
| instance_method_list = [ | | om = [field for field in dir(instance) if |
| func for func in dir(class_instance) if callable( | | callable(getattr(instance, field)) and |
| getattr( | | not field.startswith('_') and |
| class_instance, | | field not in cm] |
| func)) and not func.startswith('_') and func not in method_list] | | |
| instance_fields_list = [ | | of = [field for field in dir(instance) if |
| func for func in dir(class_instance) if not callable( | | not callable(getattr(instance, field)) and |
| getattr( | | not field.startswith('_') and |
| class_instance, | | field not in cf] |
| func)) and not func.startswith('_') and func not in fields_list] | | |
| return method_list, fields_list, instance_method_list, instance_fields_list | | 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) |
| | | |