Popular recipes tagged "meta:requires=__builtin__"http://code.activestate.com/recipes/tags/meta:requires=__builtin__/2011-02-07T06:37:52-08:00ActiveState Code RecipesBinary search function. (Python)
2011-02-07T06:37:52-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577565-binary-search-function/
<p style="color: grey">
Python
recipe 577565
by <a href="/recipes/users/4173535/">Kevin L. Sitze</a>
(<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/binary_search/">binary_search</a>, <a href="/recipes/tags/bsearch/">bsearch</a>, <a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/lower_bound/">lower_bound</a>, <a href="/recipes/tags/optimal_solution/">optimal_solution</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/upper_bound/">upper_bound</a>).
Revision 3.
</p>
<p>For a number of years Python has provided developers with the special parameters 'cmp' and 'key' on list.sort and __builtin__.sorted. However Python does not provide a built-in mechanism for doing binary searches on such sorted lists. This recipe provides a simple function that allows you to perform binary searches on your sorted sequences.</p>
Simple shelve with Linux file locking (Python)
2008-12-21T05:50:07-08:00Michael Ihdehttp://code.activestate.com/recipes/users/4168518/http://code.activestate.com/recipes/576591-simple-shelve-with-linux-file-locking/
<p style="color: grey">
Python
recipe 576591
by <a href="/recipes/users/4168518/">Michael Ihde</a>
(<a href="/recipes/tags/dynamic_method/">dynamic_method</a>, <a href="/recipes/tags/locking/">locking</a>, <a href="/recipes/tags/shelve/">shelve</a>).
</p>
<p>The shelve module is a easy way to add persistence to your application via a DBM database. However, if you have multiple reader/writer combination you need to lock the file to prevent corruption. The shelve module itself does not provide locking because it is platform specific. If you only need Linux, this simple module provide an easy way to support locking using dynamically added methods.</p>
mad debugging using __builtin__ (Python)
2008-07-28T09:40:16-07:00Robin Beckerhttp://code.activestate.com/recipes/users/880795/http://code.activestate.com/recipes/576381-mad-debugging-using-__builtin__/
<p style="color: grey">
Python
recipe 576381
by <a href="/recipes/users/880795/">Robin Becker</a>
.
</p>
<p>Nasty way to get your debugging functions available everywhere.</p>
Decorator for BindingConstants at compile time (Python)
2010-11-16T08:36:38-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/277940-decorator-for-bindingconstants-at-compile-time/
<p style="color: grey">
Python
recipe 277940
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/programs/">programs</a>).
Revision 9.
</p>
<p>Decorator for automatic code optimization. If a global is known at compile time, replace it with a constant. Fold tuples of constants into a single constant. Fold constant attribute lookups into a single constant.</p>
Builtin i18n _() function in a multi-threaded environment. (Python)
2006-01-02T10:57:10-08:00Martin Blaishttp://code.activestate.com/recipes/users/1643324/http://code.activestate.com/recipes/465756-builtin-i18n-_-function-in-a-multi-threaded-enviro/
<p style="color: grey">
Python
recipe 465756
by <a href="/recipes/users/1643324/">Martin Blais</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>Injecting _() in the __builtin__ module in order to inject global functions _() and N_() is common in applications which need i18n. This is a variation on the theme that does this in a multi-threaded environment, using threading.local from Python-2.4.</p>
"enumerate" before Python 2.3 (Python)
2005-01-30T00:36:19-08:00Nitesh Patelhttp://code.activestate.com/recipes/users/706897/http://code.activestate.com/recipes/364707-enumerate-before-python-23/
<p style="color: grey">
Python
recipe 364707
by <a href="/recipes/users/706897/">Nitesh Patel</a>
.
Revision 2.
</p>
<p>Python 2.3+ "enumerate" function is pretty handy. This bit of code should allow you to use it transparently in pre-Python 2.3 systems.</p>
Add key= argument to min(), max(), heapq.nsmallest() and nlargest() (Python)
2010-07-30T22:44:13-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/355690-add-key-argument-to-min-max-heapqnsmallest-and-nla/
<p style="color: grey">
Python
recipe 355690
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
Revision 3.
</p>
<p>Modeled after the key= argument to list.sort() and sorted().</p>
Building GTK GUIs interactively (Python)
2001-09-27T15:49:21-07:00Brian McErleanhttp://code.activestate.com/recipes/users/111980/http://code.activestate.com/recipes/65109-building-gtk-guis-interactively/
<p style="color: grey">
Python
recipe 65109
by <a href="/recipes/users/111980/">Brian McErlean</a>
(<a href="/recipes/tags/ui/">ui</a>).
Revision 3.
</p>
<p>One of pythons greatest strengths is the ability to try things interactively at the interpreter.
Using Tkinter shares this strength, since one can create buttons, windows and other widgets,
and instantly see them onscreen, click on buttons to activate callbacks and still be able to
edit and add to the widgets from the python command line.</p>
<p>While the python GTK bindings are generally excellent, one of their flaws is that this is not possible.
Before anything is actually displayed, the gtk.mainloop() function must be called, ending the
possibility of interactive manipulation.</p>
<p>This recipe is a program which simulates a python interpreter which transparently allows the user to
use gtk widgets without having to call mainloop(), in much the same way as Tk widgets.</p>
<p>This latest version contains enhancements added by Christian Robottom Reis to add readline completion support.</p>