this code is bit complexand you're probably best off tracing through it on your own to see how it works to help you studythoughhere are few highlights worth mentioning inheritance versus delegation the first-cut privacy example shown in used inheritance to mix in __setattr__ to catch accesses inheritance makes this difficulthoweverbecause differentiating between accesses from inside or outside the class is not straightforward (inside access should be allowed to run normallyand outside access should be restrictedto work around thisthe example requires inheriting classes to use __dict__ assignments to set attributes--an incomplete solution at best the version here uses delegation (embedding one object inside anotherinstead of inheritancethis pattern is better suited to our taskas it makes it much easier to distinguish between accesses inside and outside of the subject class attribute accesses from outside the subject class are intercepted by the wrapper layer' overloading methods and delegated to the class if valid accesses inside the class itself ( through self within its methodscodeare not intercepted and are allowed to run normally without checksbecause privacy is not inherited in this version decorator arguments the class decorator used here accepts any number of argumentsto name private attributes what really happensthoughis that the arguments are passed to the pri vate functionand private returns the decorator function to be applied to the subject class that isthe arguments are used before decoration ever occursprivate returns the decoratorwhich in turn "remembersthe privates list as an enclosing scope reference state retention and enclosing scopes speaking of enclosing scopesthere are actually three levels of state retention at work in this codethe arguments to private are used before decoration occurs and are retained as an enclosing scope reference for use in both ondecorator and oninstance the class argument to ondecorator is used at decoration time and is retained as an enclosing scope reference for use at instance construction time the wrapped instance object is retained as an instance attribute in the onin stance proxy objectfor use when attributes are later accessed from outside the class this all works fairly naturallygiven python' scope and namespace rules example"privateand "publicattributes