Имеется:
class MismatchError(Exception): pass class School: list = [1,2,3] def __init__(self, name: str): self.name = name def a(self, wizard): self.wizard = wizard
class MismatchError(Exception): pass class School: list = [1,2,3] def __init__(self, name: str): self.name = name def a(self, wizard): self.wizard = wizard
class MismatchError(Exception): pass class School: list = [1, 2, 3] def __init__(self, name: str): self.name = name def a(self, wizard): self.wizard = wizard if __name__ == '__main__': school = School('School') method = getattr(school, 'b', None) if method is None: raise MismatchError('Message') method()
class Test: lst = [1, 2, 3] test1 = Test() test1.lst.append(4) print(test1.lst) test2 = Test() print(test2.lst)
>>> class MismatchError(Exception): pass ... >>> class School: ... def __init__(self): ... self.a = 1 ... def __getattr__(self, attr): ... raise MismatchError("1111") ... >>> a = School() >>> a.a 1 >>> a.b Traceback (most recent call last): File "<input>", line 1, in <module> a.b File "<input>", line 5, in __getattr__ raise MismatchError("1111") MismatchError: 1111