Popular recipes by tomer filiba http://code.activestate.com/recipes/users/2520014/2013-07-31T16:04:13-07:00ActiveState Code RecipesHumanize decorator (Python)
2013-07-31T16:04:13-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/578619-humanize-decorator/
<p style="color: grey">
Python
recipe 578619
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/objects/">objects</a>, <a href="/recipes/tags/pretty/">pretty</a>, <a href="/recipes/tags/print/">print</a>).
</p>
<p>When you need to inspect Python objects in a human-readable way, you're usually required to implement a custom <code>__str__</code> or <code>__repr__</code> which are just boilerplate (e.g., <code>return "Foo(%r, %r, %r)" % (self.bar, self.spam, self.eggs)</code>. You may implement <code>__str__</code> and <code>__repr__</code> by a base-class, but it's hard to call it <em>inheritance</em> and moreover, you may wish to remove it when you're done debugging.</p>
<p>This simple (yet complete) recipe is a class decorator that injects <code>__str__</code> and <code>__repr__</code> into the class being printed. It handles nesting and even cycle detection, allowing you to just plug it into existing classes to get them pretty-printed and perhaps remove it later.</p>
Object Proxying (Python)
2006-05-26T03:44:09-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496741-object-proxying/
<p style="color: grey">
Python
recipe 496741
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/extending/">extending</a>).
</p>
<p>transparent object proxying for (almost) all objects.</p>
thread2 -- killable threads (Python)
2012-08-09T20:14:33-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496960-thread2-killable-threads/
<p style="color: grey">
Python
recipe 496960
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>A little module that extends the threading's module functionality -- allows one thread to raise exceptions in the context of another thread. By raising SystemExit, you can finally kill python threads :)</p>
weakmethod (Python)
2006-09-29T01:45:31-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/498147-weakmethod/
<p style="color: grey">
Python
recipe 498147
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/extending/">extending</a>).
</p>
<p>Weakly-bound methods: use this decorator to create methods that weakly-reference their instance (im_self). This means that the method itself will not keep the object alive. Useful for callbacks, caches, and avoiding cyclic references.</p>
Templite (Python)
2006-05-16T17:35:27-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496702-templite/
<p style="color: grey">
Python
recipe 496702
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/text/">text</a>).
Revision 3.
</p>
<p>A light-weight, fully functional, general purpose templating engine, in just 40 lines of code</p>
Real Mixins (Python)
2006-09-22T14:58:53-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/498124-real-mixins/
<p style="color: grey">
Python
recipe 498124
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/extending/">extending</a>).
Revision 2.
</p>
<p>This code here creates real mixed-in classes: it actually merges one class into another (c-python specific), taking care of name-mangling, some complications with __slots__, and everything else. As a side-effect, you can also use it to mix modules into classes. Similar to ruby's include statement.</p>
module mixins (Python)
2006-08-29T10:02:57-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496997-module-mixins/
<p style="color: grey">
Python
recipe 496997
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/extending/">extending</a>).
</p>
<p>Module mixins allow you to inherit from <em>modules</em>. This is how ruby achieves multiple inheritance, and I just wanted to show it's possible in python as well.</p>
Container (Python)
2006-05-13T07:37:50-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496697-container/
<p style="color: grey">
Python
recipe 496697
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/extending/">extending</a>).
</p>
<p>A generic attribute container, with pretty printing and recursion protection</p>
ShelfProxy (Python)
2006-05-26T14:40:18-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496742-shelfproxy/
<p style="color: grey">
Python
recipe 496742
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/extending/">extending</a>).
Revision 2.
</p>
<p>Uses object proxying to expose a more intuitive interface to shelves. Requires the Proxy recipe (<a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496741%29." rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496741).</a></p>
helement (Python)
2006-05-26T15:45:14-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496743-helement/
<p style="color: grey">
Python
recipe 496743
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/text/">text</a>).
Revision 2.
</p>
<p>HTML-element tree declaration that emits nice HTML</p>
weakattr (Python)
2006-06-04T15:46:28-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496771-weakattr/
<p style="color: grey">
Python
recipe 496771
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/extending/">extending</a>).
Revision 2.
</p>
<p>Weak attributes - cyclic references made easy</p>
ExceptionContainer (Python)
2006-05-13T07:43:50-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496698-exceptioncontainer/
<p style="color: grey">
Python
recipe 496698
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/extending/">extending</a>).
</p>
<p>an Exception base-class that supports keyword arguments and pretty printing</p>