Top-rated recipes tagged "object"http://code.activestate.com/recipes/tags/object/top/2016-02-25T19:40:33-08:00ActiveState Code RecipesSimple tool for simulating classes using closures and nested scopes (Python) 2012-04-11T06:21:18-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/578091-simple-tool-for-simulating-classes-using-closures-/ <p style="color: grey"> Python recipe 578091 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/closure/">closure</a>, <a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/oriented/">oriented</a>). Revision 9. </p> <p>Closured-based alternative to normal classes. Allows a faster, cleaner coding style at the expense of some functionality.</p> A Simpler Namespace Class (Python) 2013-02-14T17:42:24-08:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/578141-a-simpler-namespace-class/ <p style="color: grey"> Python recipe 578141 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/namespaces/">namespaces</a>, <a href="/recipes/tags/object/">object</a>). Revision 3. </p> <p>A very simple, attribute-based namespace type (and one offspring). Everyone's written one of these...</p> Simple graph algorithms with a modular design (Python) 2011-04-21T13:40:32-07:00jimmy2timeshttp://code.activestate.com/recipes/users/4177690/http://code.activestate.com/recipes/577668-simple-graph-algorithms-with-a-modular-design/ <p style="color: grey"> Python recipe 577668 by <a href="/recipes/users/4177690/">jimmy2times</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/breadth/">breadth</a>, <a href="/recipes/tags/depth/">depth</a>, <a href="/recipes/tags/directed/">directed</a>, <a href="/recipes/tags/first/">first</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/oriented/">oriented</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/theory/">theory</a>, <a href="/recipes/tags/undirected/">undirected</a>, <a href="/recipes/tags/visit/">visit</a>). Revision 7. </p> <p>The purpose of this recipe is to look at algorithmic graph theory from an object-oriented perspective.</p> <p>A graph is built on top of a dictionary indexed by its vertices, each item being the set of neighbours of the key vertex. This ensures that iterating through the neighbours of a vertex is still efficient in sparse graphs (as with adjacency lists) while at the same time checking for adjacency is expected constant-time (as with the adjacency matrix).</p> <p>Any valid class of graph must implement the interface defined by AbstractGraph.</p> <p>A generic search algorithm takes as input a graph, source and target vertices and a queue. A queue must implement the methods Q.get(), Q.put() and Q.empty() in such a way to get the desired order in visiting the vertices.</p> <p>Given this pattern, breadth-first and depth-first search are essentially defined by the corresponding expansion policies: the first one uses an actual FIFO queue, the second one a LIFO queue (or stack).</p> Python method chaining examples (Python) 2016-02-25T19:40:33-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580616-python-method-chaining-examples/ <p style="color: grey"> Python recipe 580616 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/chaining/">chaining</a>, <a href="/recipes/tags/methods/">methods</a>, <a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This recipe shows a few examples of doing method chaining in Python.</p> extending xrange to support slicing and indexing (Python) 2012-03-13T16:13:16-07:00Garretthttp://code.activestate.com/recipes/users/4181290/http://code.activestate.com/recipes/578070-extending-xrange-to-support-slicing-and-indexing/ <p style="color: grey"> Python recipe 578070 by <a href="/recipes/users/4181290/">Garrett</a> (<a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xrange/">xrange</a>). </p> <p>an object which extends the xrange object to support slicing and indexing (simple)</p> XML To Python object(next generation) with real life example: fetching US Treasure Curve (Python) 2012-02-14T01:24:28-08:00Boris Katshttp://code.activestate.com/recipes/users/4180778/http://code.activestate.com/recipes/578032-xml-to-python-objectnext-generation-with-real-life/ <p style="color: grey"> Python recipe 578032 by <a href="/recipes/users/4180778/">Boris Kats</a> (<a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 11. </p> <p>This middle sized python class will populate himself from any xml with reasonable restrictions.</p> CLOS-like around/before/after auxiliary methods (Python) 2011-08-25T22:59:22-07:00Jan Kaliszewskihttp://code.activestate.com/recipes/users/4172762/http://code.activestate.com/recipes/577859-clos-like-aroundbeforeafter-auxiliary-methods/ <p style="color: grey"> Python recipe 577859 by <a href="/recipes/users/4172762/">Jan Kaliszewski</a> (<a href="/recipes/tags/auxiliary/">auxiliary</a>, <a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/clos/">clos</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/method/">method</a>, <a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/super/">super</a>). </p> <p>This module provides an easy way to define and use your own <strong>around/before/after auxiliary methods</strong>, similar to <a href="http://www.aiai.ed.ac.uk/~jeff/clos-guide.html#meth-comb">those used in CLOS</a> (Common Lisp Object System).</p> Fnct.D, comprehensive Bash-shell coding scheme. (Bash) 2010-11-01T00:29:09-07:00Patrick Riendeauhttp://code.activestate.com/recipes/users/4175653/http://code.activestate.com/recipes/577446-fnctd-comprehensive-bash-shell-coding-scheme/ <p style="color: grey"> Bash recipe 577446 by <a href="/recipes/users/4175653/">Patrick Riendeau</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/oriented/">oriented</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/system/">system</a>). </p> <p>A Bash compromising shell-module to pre-introduce object-oriented Bash-code.</p> Object snoop - experiment with Python special methods (Python) 2010-09-05T17:54:50-07:00Wai Yip Tunghttp://code.activestate.com/recipes/users/2382677/http://code.activestate.com/recipes/577383-object-snoop-experiment-with-python-special-method/ <p style="color: grey"> Python recipe 577383 by <a href="/recipes/users/2382677/">Wai Yip Tung</a> (<a href="/recipes/tags/metaprogramming/">metaprogramming</a>, <a href="/recipes/tags/methods/">methods</a>, <a href="/recipes/tags/object/">object</a>). </p> <p>In Python, classes can define their own behavior with respect to language operators. For example, if a class defines __getitem__(), then x[i], where x is an instance of the clas, will be execute by a call to x.__getitem__(i).</p> <p>While Python has an extensive documentation on the special methods, reading a specification may not be the best way to reveal the intricate details. <strong>object_snoop</strong> allows user to observe how Python expressions and statements are translated into special method calls. object_snoop defines most special methods. It simple print a trace and returns a fixed but sensible result. Users are invited to build complex expressions to experiment how Python special methods work.</p> Object Wrapper (Python) 2010-05-05T17:02:42-07:00Dmitryhttp://code.activestate.com/recipes/users/4173772/http://code.activestate.com/recipes/577215-object-wrapper/ <p style="color: grey"> Python recipe 577215 by <a href="/recipes/users/4173772/">Dmitry</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/wrapper/">wrapper</a>). </p> <p>There is classical wrapper on Python language. If you have only object and can't change object generation you can use this class.</p> Immutable object(subclass) (Python) 2010-04-23T08:30:50-07:00Dmitryhttp://code.activestate.com/recipes/users/4173772/http://code.activestate.com/recipes/577207-immutable-objectsubclass/ <p style="color: grey"> Python recipe 577207 by <a href="/recipes/users/4173772/">Dmitry</a> (<a href="/recipes/tags/immutable/">immutable</a>, <a href="/recipes/tags/object/">object</a>). Revision 2. </p> <p>Useful class and decorator for create immutable objects. Decorator mutablemethod used for define mutable methods.</p>