Most viewed recipes tagged "programs" Code RecipesSpreadsheet (Python) 2004-12-03T09:13:43-08:00Raymond Hettinger <p style="color: grey"> Python recipe 355045 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Use eval() to drive spreadsheet style logic. The sleeper feature of Py2.4 is the ability to use any object with a mapping interface as the locals argument to eval().</p> List classes, methods and functions in a module (Python) 2008-10-22T08:15:26-07:00Anand <p style="color: grey"> Python recipe 553262 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 5. </p> <p>The recipe provides a method "describe" which takes a module as argument and describes classes, methods and functions in the module. The method/function description provides information on the function/method arguments using the inspect module.</p> Enums for Python (Python) 2001-08-23T14:57:17-07:00Will Ware <p style="color: grey"> Python recipe 67107 by <a href="/recipes/users/98156/">Will Ware</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>I once tried to give Python something like C's enums, as described here: <a href="" rel="nofollow"></a> That approach tried to assign to a dictionary returned by the locals() function, intending that such assignments would become class attributes. The Tim-bot explained to me the errors of my ways. The quest for the perfect Python enum goes on.</p> Decorator for BindingConstants at compile time (Python) 2010-11-16T08:36:38-08:00Raymond Hettinger <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> curry -- associating parameters with a function (Python) 2001-04-18T03:32:32-07:00Scott David Daniels <p style="color: grey"> Python recipe 52549 by <a href="/recipes/users/98131/">Scott David Daniels</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>In functional programming, currying is a way to bind arguments with a function and wait for the rest of the arguments to show up later. You "curry in" the first few parameters to a function, giving you a function that takes subsequent parameters as input and calls the original with all of those parameters. This recipe uses a class instance to hold the parameters before their first use. For example:</p> <pre class="prettyprint"><code>double = curry(operator.mul, 2) triple = curry(operator.mul, 3) </code></pre> Simple Average Calculation (Python) 2012-07-11T12:27:59-07:00Stephen Chappell <p style="color: grey"> Python recipe 440625 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Here is a simple program that can average a list of numbers. I wrote this to introduce someone to the language that we all use and love. :D The program may be simple, but it shows how easily a simple but useful program can turn out to be.</p> Linear equations solver in 3 lines (Python) 2005-01-31T22:06:30-08:00Maxim Krikun <p style="color: grey"> Python recipe 365013 by <a href="/recipes/users/1085177/">Maxim Krikun</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Just a little bit of hack: a linear equations solver using eval and built-in complex numbers:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; solve("x - 2*x + 5*x - 46*(235-24) = x + 2") 3236.0 </code></pre> First Class Enums in Python (Python) 2005-05-09T16:53:44-07:00Zoran Isailovski <p style="color: grey"> Python recipe 413486 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 7. </p> <p>True immutable symbolic enumeration with qualified value access.</p> Pythologic -- Prolog syntax in Python (Python) 2004-09-01T21:11:14-07:00Shai Berger <p style="color: grey"> Python recipe 303057 by <a href="/recipes/users/2014324/">Shai Berger</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Some of Python's powerful meta-programming features are used to enable writing Python functions which include Prolog-like statements. Such functions load a Prolog-like database. When coupled with a suitable inference engine for logic databases, this is a way to add logical programming -- the last unsupported major paradigm -- to Python. Start at the bottom of the code for an example of the enabled syntax.</p> Colorize Python source using the built-in tokenizer (Python) 2001-04-06T23:05:53-07:00Jürgen Hermann <p style="color: grey"> Python recipe 52298 by <a href="/recipes/users/98061/">Jürgen Hermann</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>This code is part of MoinMoin (<a href="" rel="nofollow"></a>) and converts Python source code to HTML markup, rendering comments, keywords, operators, numeric and string literals in different colors.</p> <p>It shows how to use the built-in keyword, token and tokenize modules to scan Python source code and re-emit it with no changes to its original formatting (which is the hard part).</p> <p>The test code at the bottom of the module formats itself and launches a browser with the result.</p> Extracting *.tar.gz files in Windows ... (Python) 2005-11-01T10:36:05-08:00Stephen Chappell <p style="color: grey"> Python recipe 442503 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>This recipe is meant to be used as a commmand line *.tar.gz file extractor. If it fails, then a usage note is given. It may be small, but it can be very useful for some people.</p> Skeleton script Hello World (Python) 2007-12-07T15:32:02-08:00Noah Spurrier <p style="color: grey"> Python recipe 528877 by <a href="/recipes/users/103276/">Noah Spurrier</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 5. </p> <p>I write a lot of small scripts in Python. This is the template that I use to start most of my scripts. This gets me started with good documentation, argument parsing, and error handling.</p> prompt the user for confirmation (Python) 2008-01-02T08:35:30-08:00Raghuram Devarakonda <p style="color: grey"> Python recipe 541096 by <a href="/recipes/users/4084209/">Raghuram Devarakonda</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Displays a prompt and queries the user for positive or negative confirmation.</p> Quote python strings for safe use in POSIX shells (Python) 2006-10-16T10:30:58-07:00Richard Philips <p style="color: grey"> Python recipe 498202 by <a href="/recipes/users/98125/">Richard Philips</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Often one has to quote a python string so that the result can be used as an argument to a command running in a POSIX shell.</p> <p>The function QuoteForPOSIX can be used with sh, bash, csh, ksh</p> Twisted / BitTorrent :: Client / Server (Python) 2005-10-30T01:24:39-07:00Jonathan Kolyer <p style="color: grey"> Python recipe 440555 by <a href="/recipes/users/452108/">Jonathan Kolyer</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>Two modules that run a BitTorrent server, and uses Twisted as a client to coordinate control-message passing, and progress monitoring. The server can be run as a separate process, or as a thread within the client -- the same messages can be passed back and forth.</p> <p>Control messages can cancel individual downloads (or the whole process), as well as pause downloading. Progress queries can be invoked through the client, which will ping the server, and report back each downloads' progress.</p> Regular expression for python string literals (Python) 2006-03-10T20:52:36-08:00Edward Loper <p style="color: grey"> Python recipe 475109 by <a href="/recipes/users/2637812/">Edward Loper</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>A regular expression that matches Python string literals. Tripple-quoted, unicode, and raw strings are supported.</p> Automate CATIA V5 with Python and Pywin32 (Python) 2008-04-02T22:22:46-07:00Mustafa Görmezer <p style="color: grey"> Python recipe 347243 by <a href="/recipes/users/2091634/">Mustafa Görmezer</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 5. </p> <p>This is small application shows how to automate the CAD/PLM Software CATIA V5 via win32com. CATIA V5 must be installed and should be running when testing the application. Other examples you can find on <a href="" rel="nofollow"></a> .</p> Pyscanlogger - Python Port scan detector (Python) 2010-03-17T07:27:15-07:00Anand <p style="color: grey"> Python recipe 576690 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/security/">security</a>). Revision 5. </p> <p>A pure Python program to detect network port scanning attacks. Currently logs different TCP port scans. Can run in the background like a daemon and log attacks to a log file.</p> pypopper - Python POP3 Server (Python) 2007-10-24T18:52:39-07:00Daniel Miller <p style="color: grey"> Python recipe 534131 by <a href="/recipes/users/4016391/">Daniel Miller</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>While developing &lt;a href=""&gt;ThunderBayes&lt;/a&gt; (an extension for Thunderbird) I wrote this simple POP3 server to serve a message to my ThunderBayes test setup.</p> Simple lockfile to detect previous instances of app (Python) 2007-03-05T21:54:12-08:00Jordan Callicoat <p style="color: grey"> Python recipe 498171 by <a href="/recipes/users/2948075/">Jordan Callicoat</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>This recipe implements a simple lockfile to ensure that only one instance of an app is alive at any given time.</p> <p>1.2 Added documentation and cleaned up a bit.</p>