Top-rated recipes tagged "descriptors"http://code.activestate.com/recipes/tags/descriptors/top/2011-08-12T23:42:27-07:00ActiveState Code RecipesLazy Dynamic Binding on Classes (You'll Never Go Back) (Python) 2011-08-12T23:42:27-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577745-lazy-dynamic-binding-on-classes-youll-never-go-bac/ <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="http://code.activestate.com/recipes/577746/">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 Baillethttp://code.activestate.com/recipes/users/4175355/http://code.activestate.com/recipes/577426-auto-named-decriptors/ <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>