Latest recipes tagged "descriptors" Code RecipesLazy Dynamic Binding on Classes (You'll Never Go Back) (Python) 2011-08-12T23:42:27-07:00Eric Snow <p style="color: grey"> Python recipe 577745 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/descriptor/">descriptor</a>, <a href="/recipes/tags/descriptors/">descriptors</a>). Revision 4. </p> <p>This recipe provides a descriptor class and a decorator to make the deferred binding. Before the first access to that name, the __dict__ of the class will have the descriptor object. After that first access it will have whatever was returned by the first access.</p> <p>One big advantage of deferring the binding is that the class object will be available at that time and can be passed to the object. During normal class creation the class body is exec'd before the class object is created, so the objects bound there can't be passed the class.</p> <p><a href="">Recipe #577746</a> provides a concrete example of how the deferred_binder can be used.</p> Auto Named Decriptors (Python) 2010-10-19T22:55:16-07:00Aloys Baillet <p style="color: grey"> Python recipe 577426 by <a href="/recipes/users/4175355/">Aloys Baillet</a> (<a href="/recipes/tags/automatically/">automatically</a>, <a href="/recipes/tags/constants/">constants</a>, <a href="/recipes/tags/descriptors/">descriptors</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/name/">name</a>, <a href="/recipes/tags/string/">string</a>). Revision 3. </p> <p>Using named Descriptors? Tired of duplicating the name of the instance in a string? A small metaclass can solve this.</p>