Most viewed recipes tagged "programs" but not "ssh" and "postgres"http://code.activestate.com/recipes/tags/-ssh-postgres+programs/views/2012-07-11T12:27:59-07:00ActiveState Code RecipesSpreadsheet (Python)
2004-12-03T09:13:43-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/355045-spreadsheet/
<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:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/553262-list-classes-methods-and-functions-in-a-module/
<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 Warehttp://code.activestate.com/recipes/users/98156/http://code.activestate.com/recipes/67107-enums-for-python/
<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="http://groups.google.com/groups?selm=G6qzLy.6Fo%2540world.std.com" rel="nofollow">http://groups.google.com/groups?selm=G6qzLy.6Fo%40world.std.com</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 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>
curry -- associating parameters with a function (Python)
2001-04-18T03:32:32-07:00Scott David Danielshttp://code.activestate.com/recipes/users/98131/http://code.activestate.com/recipes/52549-curry-associating-parameters-with-a-function/
<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 Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/440625-simple-average-calculation/
<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 Krikunhttp://code.activestate.com/recipes/users/1085177/http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/
<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>>>> 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 Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/413486-first-class-enums-in-python/
<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 Bergerhttp://code.activestate.com/recipes/users/2014324/http://code.activestate.com/recipes/303057-pythologic-prolog-syntax-in-python/
<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 Hermannhttp://code.activestate.com/recipes/users/98061/http://code.activestate.com/recipes/52298-colorize-python-source-using-the-built-in-tokenize/
<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="http://moin.sourceforge.net/" rel="nofollow">http://moin.sourceforge.net/</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 Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/442503-extracting-targz-files-in-windows/
<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 Spurrierhttp://code.activestate.com/recipes/users/103276/http://code.activestate.com/recipes/528877-skeleton-script-hello-world/
<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 Devarakondahttp://code.activestate.com/recipes/users/4084209/http://code.activestate.com/recipes/541096-prompt-the-user-for-confirmation/
<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 Philipshttp://code.activestate.com/recipes/users/98125/http://code.activestate.com/recipes/498202-quote-python-strings-for-safe-use-in-posix-shells/
<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 Kolyerhttp://code.activestate.com/recipes/users/452108/http://code.activestate.com/recipes/440555-twisted-bittorrent-client-server/
<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 Loperhttp://code.activestate.com/recipes/users/2637812/http://code.activestate.com/recipes/475109-regular-expression-for-python-string-literals/
<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örmezerhttp://code.activestate.com/recipes/users/2091634/http://code.activestate.com/recipes/347243-automate-catia-v5-with-python-and-pywin32/
<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="http://win32com.goermezer.de/content/view/29/291/" rel="nofollow">http://win32com.goermezer.de/content/view/29/291/</a> .</p>
Pyscanlogger - Python Port scan detector (Python)
2010-03-17T07:27:15-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576690-pyscanlogger-python-port-scan-detector/
<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 Millerhttp://code.activestate.com/recipes/users/4016391/http://code.activestate.com/recipes/534131-pypopper-python-pop3-server/
<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 <a href="http://pieces.openpolitics.com/thunderbayes/">ThunderBayes</a> (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 Callicoathttp://code.activestate.com/recipes/users/2948075/http://code.activestate.com/recipes/498171-simple-lockfile-to-detect-previous-instances-of-ap/
<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>