Popular recipes tagged "meta:loc=103"http://code.activestate.com/recipes/tags/meta:loc=103/2014-02-13T04:33:19-08:00ActiveState Code RecipesBader-Offer Method (Hagenbach-Bischoff) (Python)
2014-02-13T04:33:19-08:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578831-bader-offer-method-hagenbach-bischoff/
<p style="color: grey">
Python
recipe 578831
by <a href="/recipes/users/4187847/">elazar</a>
(<a href="/recipes/tags/calculation/">calculation</a>).
Revision 3.
</p>
<p>A recipe for calculating the seats allocated to each party in the Knesset.</p>
<p>More information:</p>
<ul>
<li><a href="http://www.knesset.gov.il/lexicon/eng/seats_eng.htm" rel="nofollow">http://www.knesset.gov.il/lexicon/eng/seats_eng.htm</a></li>
<li><a href="https://en.wikipedia.org/wiki/Hagenbach-Bischoff_system" rel="nofollow">https://en.wikipedia.org/wiki/Hagenbach-Bischoff_system</a></li>
<li>(Hebrew) <a href="http://www.bechirot.gov.il/elections19/heb/about/MandatesSystem.aspx" rel="nofollow">http://www.bechirot.gov.il/elections19/heb/about/MandatesSystem.aspx</a></li>
</ul>
Pachebel Cannon in C (Python)
2013-08-13T21:08:45-07:00Bhttp://code.activestate.com/recipes/users/4187518/http://code.activestate.com/recipes/578640-pachebel-cannon-in-c/
<p style="color: grey">
Python
recipe 578640
by <a href="/recipes/users/4187518/">B</a>
(<a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/cannon/">cannon</a>, <a href="/recipes/tags/in/">in</a>, <a href="/recipes/tags/music/">music</a>, <a href="/recipes/tags/pachebel/">pachebel</a>).
</p>
<p>only works in windows</p>
Text Editor in Python 3.3 (Python)
2013-06-19T15:58:17-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578569-text-editor-in-python-33/
<p style="color: grey">
Python
recipe 578569
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/text_processing/">text_processing</a>).
</p>
<p>This is a simple text editor written in Python using <code>tkinter</code> for graphics.</p>
<p>Check out Captain DeadBones' <a href="http://thelivingpearl.com/">Chronicles</a> blog.</p>
IFS fractals using automatic probability distribution (Python)
2012-03-11T21:50:31-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578069-ifs-fractals-using-automatic-probability-distribut/
<p style="color: grey">
Python
recipe 578069
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>To draw an IFS fractal probabilities of each transformation must be given normally.
This code calculates the probabilities using a heuristic instead.
The bounding rectangle of the fractal also calculated automatically. </p>
Using vlc.py to record an mp3 and save a cue file (Python)
2011-07-25T15:55:38-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/577802-using-vlcpy-to-record-an-mp3-and-save-a-cue-file/
<p style="color: grey">
Python
recipe 577802
by <a href="/recipes/users/2667360/">Anton Vredegoor</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/recording/">recording</a>).
Revision 2.
</p>
<p>This is an example of how to use vlc.py . It records an mp3 file from an online audio stream, using the track announcements to write an accompanying cue file. </p>
Backwards Compatibility part 4... (Python)
2011-10-10T19:39:54-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577903-backwards-compatibility-part-4/
<p style="color: grey">
Python
recipe 577903
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/all_versions/">all_versions</a>, <a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/backwards_compatibility/">backwards_compatibility</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>).
</p>
<p>Some example lines to add to any test code you write that work from Python 1.4.0 to 3.2.2
on various platforms.</p>
<p>It is all Public Domain and you can do with it as you please...</p>
<p>I really don't care how you vote and/or rate this as I try to write Python code for my
usage to work on the platforms and versions inside the code.</p>
<p>Some people will know this but very MANY won't and there will be more to come that involve
platform and version compatibility...</p>
<p>Enjoy finding simple solutions to often VERY difficult problems...</p>
<p>(Watch out for word wrapping, etc...)</p>
<p>Bazza, G0LCU...</p>
Convert a transcript with Ansi escape sequences to HTML (Python)
2010-10-09T22:29:42-07:00Muhammad Alkarourihttp://code.activestate.com/recipes/users/4049383/http://code.activestate.com/recipes/577349-convert-a-transcript-with-ansi-escape-sequences-to/
<p style="color: grey">
Python
recipe 577349
by <a href="/recipes/users/4049383/">Muhammad Alkarouri</a>
(<a href="/recipes/tags/ansi/">ansi</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/text/">text</a>).
Revision 2.
</p>
<p>This is a stab at converting a transcript generated by the Unix <code>script</code> command that uses ANSI escape sequences, used to colour the terminal, to HTML.</p>
The goto decorator (Python)
2009-11-03T13:14:57-08:00Carl Cereckehttp://code.activestate.com/recipes/users/4172182/http://code.activestate.com/recipes/576944-the-goto-decorator/
<p style="color: grey">
Python
recipe 576944
by <a href="/recipes/users/4172182/">Carl Cerecke</a>
(<a href="/recipes/tags/bytecodes/">bytecodes</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/goto/">goto</a>).
Revision 5.
</p>
<p>A function-decorator that provides the goto command.</p>
simple recurse class (Python)
2008-08-26T01:29:22-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576449-simple-recurse-class/
<p style="color: grey">
Python
recipe 576449
by <a href="/recipes/users/4166679/">alexander baker</a>
(<a href="/recipes/tags/recurse/">recurse</a>, <a href="/recipes/tags/unittest/">unittest</a>).
Revision 2.
</p>
<h4>Class to encapsualte building a file</h4>
<h4>from a path</h4>
object finalization without __del__ and without hassles (Python)
2007-05-11T09:32:33-07:00Antoine Pitrouhttp://code.activestate.com/recipes/users/4054086/http://code.activestate.com/recipes/519621-object-finalization-without-__del__-and-without-ha/
<p style="color: grey">
Python
recipe 519621
by <a href="/recipes/users/4054086/">Antoine Pitrou</a>
(<a href="/recipes/tags/oop/">oop</a>).
Revision 4.
</p>
<p>The well-known way to avoid __del__ (and its problems when the object to be deleted is involved in a reference cycle) is to use a finalization callback on a weakref.</p>
<p>This recipe simply makes it easier to write such "finalizable" objects by allowing to write the finalizer as a __finalize__ method (a bit similar to a __del__ method, but not exactly as we'll see).</p>
<p>The first step is to call the bind_finalizer(*attrs) method on your instance; you must give bind_finalizer a list of attribute names necessary for the finalizer to operate, and it will construct a "ghost object" holding those attributes (for example, if you have a "socket" attribute you want to close, you will include "socket" in the arguments to bind_finalizer, which in turn will bind a "socket" attribute on the ghost object). The ghost object has the same class as the original self, so you will be able to call instance methods and use class variables in the finalizer as well.</p>
<p>Please note: the ghost object is created and its attributes are bound <em>as soon as</em> bind_finalizer() is called, so their values must have been properly initialized. A practical idiom is probably to call bind_finalizer() at the end of your constructor. Creating the ghost ignores any __new__ or __init__ method you have defined, so you don't have to worry about constructor signature or unwanted side effects.</p>
<p>Your __finalize__ method must be written as a normal method, except that it can only access those instance attributes whose names you gave to bind_finalizer. This is because __finalize__ gets a "ghost instance" instead of the original instance.</p>
<p>Finally, there is a remove_finalizer() which does the obvious. Call it when the resources have been somehow freed manually and automatic finalization is not useful anymore.</p>
<p>With this recipe, you have an object-oriented finalization scheme which still works as required when your instance is part of a reference cycle to be broken by the Garbage Collector. Also, it doesn't use metaclasses which makes it easier to re-use if you have your own metaclasses.</p>
<p>You can find hereafter the code for the Finalizeable class, as well as an example TransactionBase class which helps writing objects with transaction-like behaviour and optional automatic rollback on object destruction.
(but the interesting stuff is really in Finalizable)</p>
Remove FTP directory walk() equivalent. (Python)
2006-12-18T11:31:55-08:00Martin Blaishttp://code.activestate.com/recipes/users/1643324/http://code.activestate.com/recipes/499334-remove-ftp-directory-walk-equivalent/
<p style="color: grey">
Python
recipe 499334
by <a href="/recipes/users/1643324/">Martin Blais</a>
.
</p>
<p>A routine much like os.walk() that iterates over the directories and files of a remote FTP storage.</p>
Attributes WithProtection without pain (Python)
2006-08-02T02:58:31-07:00kay schluehrhttp://code.activestate.com/recipes/users/2398921/http://code.activestate.com/recipes/496930-attributes-withprotection-without-pain/
<p style="color: grey">
Python
recipe 496930
by <a href="/recipes/users/2398921/">kay schluehr</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>This recipe enables proper protection of attributes that are mangled with Pythons privacy indicator: the single underscore _.</p>
Changing the background color of the menu bar in a wxPython Windows app (Python)
2005-09-02T19:09:28-07:00Kartic Krishnamurthyhttp://code.activestate.com/recipes/users/2570233/http://code.activestate.com/recipes/440507-changing-the-background-color-of-the-menu-bar-in-a/
<p style="color: grey">
Python
recipe 440507
by <a href="/recipes/users/2570233/">Kartic Krishnamurthy</a>
(<a href="/recipes/tags/ui/">ui</a>).
Revision 2.
</p>
<p>Using win32 API to change the background color of the menubar/menu items in a wxPython app without affecting system-wide settings.</p>
autosuper to the limit (Python)
2005-05-01T20:27:44-07:00Diego Novellahttp://code.activestate.com/recipes/users/2425477/http://code.activestate.com/recipes/412856-autosuper-to-the-limit/
<p style="color: grey">
Python
recipe 412856
by <a href="/recipes/users/2425477/">Diego Novella</a>
(<a href="/recipes/tags/oop/">oop</a>).
Revision 2.
</p>
<p>This recipe comes from an idea to "improve" Tim Delaney's "autosuper" recipe (<a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195</a>) by using a similar approach but with no need to inherit a class from 'autosuper'. It is now a free function to be used inside a method body whithout the need to pass it the 'self' object:
class C(object):
def foo(self,<em>a,<strong>k):
# do something
autosuper(</em>a,</strong>k)
# do something</p>
A simple equation solver using attribute access and introspection (Python)
2004-09-03T16:29:43-07:00David Klaffenbachhttp://code.activestate.com/recipes/users/2007923/http://code.activestate.com/recipes/303396-a-simple-equation-solver-using-attribute-access-an/
<p style="color: grey">
Python
recipe 303396
by <a href="/recipes/users/2007923/">David Klaffenbach</a>
.
</p>
<p>This is a little equation solver somewhat modelled on the solvers available in some scientific calculators. You pass it a function which returns zero when the desired relation is true. Once you create a solver object, you can solve for any variable.</p>
Read a file backwords (Python)
2004-03-25T17:58:37-08:00Matthew Sherbornehttp://code.activestate.com/recipes/users/1508183/http://code.activestate.com/recipes/276149-read-a-file-backwords/
<p style="color: grey">
Python
recipe 276149
by <a href="/recipes/users/1508183/">Matthew Sherborne</a>
.
</p>
<p>Read a file line by line starting at the end</p>
Generic filter logic strategy (Python)
2003-09-18T23:35:35-07:00Robert Brewerhttp://code.activestate.com/recipes/users/1354305/http://code.activestate.com/recipes/223612-generic-filter-logic-strategy/
<p style="color: grey">
Python
recipe 223612
by <a href="/recipes/users/1354305/">Robert Brewer</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>By storing an object's data in a dictionary, you can easily create a Filter class which tests a given object against a set of nested inclusion rules. This works particularly well for database filtering.</p>
Drawing inheritance diagrams with "Dot" (Python)
2003-08-03T07:54:55-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/213898-drawing-inheritance-diagrams-with-dot/
<p style="color: grey">
Python
recipe 213898
by <a href="/recipes/users/1122360/">Michele Simionato</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>Dot is a very nice graph description language developed
at MIT and available for free at <a href="http://www.graphviz.org/" rel="nofollow">http://www.graphviz.org/</a> .
Combined with Python, it makes an ideal tool to automatically
generate diagrams.
I will describe here a short recipe which produces beautiful
inheritance diagrams for Python classes (and metaclasses too).
In particular the recipe allows to display the MRO (Method
Resolution Order) for complicate inheritance hierarchies.</p>