acct mangled to _acct if value raise valueerror('invalid age'elif name ='acct'name '_acctvalue value replace('-'''if len(value!self acctlenraise typeerror('invald acct number'elif name ='remain'raise typeerror('cannot set remain'self __dict__[namevalue avoid looping (or via objectwhen this code is run with either test scriptit produces the same output (with different class name) :\codepy - validate_tester py validate_getattr same output as propertiesexcept class name :\codepy - validate_tester py validate_getattr same output as instance-state descriptorsexcept class name using __getattribute__ to validate our final variant uses the __getattribute__ catchall to intercept attribute fetches and manage them as needed every attribute fetch is caught hereso we test the attribute names to detect managed attributes and route all others to the superclass for normal fetch processing this version uses the same __setattr__ to catch assignments as the prior version the code works very much like the __getattr__ versionso won' repeat the full description here notethoughthat because every attribute fetch is routed to __getat tribute__we don' need to mangle names to intercept them here (acct is stored as accton the other handthis code must take care to route nonmanaged attribute fetches to superclass to avoid looping or extra calls also notice that this version incurs extra calls for both setting and fetching unmanaged attributes ( addr)if speed is paramountthis alternative may be the slowest of the bunch for comparison purposesthis version amounts to lines of codejust like the prior versionand includes the requisite object derivation for compatibilitylike properties and descriptors__getattribute__ is new-style class toolfile validate_getattribute py class cardholder(object)acctlen retireage def __init__(selfacctnameageaddr)self acct acct self name name self age age self addr addr need "(object)in only class data instance data these trigger __setattr__ too acct not mangledname tested addr is not managed exampleattribute validations