CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Thu, 17 Jul 2025 17:22:22 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20090419080539
location: https://web.archive.org/web/20090419080539/https://code.activestate.com/feeds/langs/python/
server-timing: captures_list;dur=0.732638, exclusion.robots;dur=0.030983, exclusion.robots.policy;dur=0.013817, esindex;dur=0.014488, cdx.remote;dur=132.322168, LoadShardBlock;dur=436.237436, PetaboxLoader3.datanode;dur=139.940815, PetaboxLoader3.resolve;dur=155.153800
x-app-server: wwwb-app210
x-ts: 302
x-tr: 598
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app210; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Thu, 17 Jul 2025 17:22:23 GMT
content-type: application/atom+xml
content-length: 23188
x-archive-orig-date: Sun, 19 Apr 2009 08:04:56 GMT
x-archive-orig-server: Apache/2.2.3 (CentOS)
x-archive-orig-content-length: 23188
x-archive-orig-expires: Sun, 19 Apr 2009 08:14:57 GMT
x-archive-orig-vary: Cookie
x-archive-orig-last-modified: Sun, 19 Apr 2009 08:04:57 GMT
x-archive-orig-etag: 1d301b8a2266fef57077e5f85d442eba
x-archive-orig-cache-control: max-age=600
x-archive-orig-age: 38
x-archive-orig-via: 1.0 box19.activestate.com:3129 (squid/2.6.STABLE21)
x-archive-orig-connection: close
cache-control: max-age=1800
x-archive-guessed-content-type: text/xml
x-archive-guessed-charset: utf-8
memento-datetime: Sun, 19 Apr 2009 08:05:39 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Wed, 13 Aug 2008 15:40:56 GMT", ; rel="prev memento"; datetime="Sat, 11 Apr 2009 04:19:29 GMT", ; rel="memento"; datetime="Sun, 19 Apr 2009 08:05:39 GMT", ; rel="next memento"; datetime="Thu, 18 Jun 2009 23:17:23 GMT", ; rel="last memento"; datetime="Fri, 28 Jun 2024 22:06:13 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_9_20090419014904_crawl102-c/52_9_20090419080316_crawl103.arc.gz
server-timing: captures_list;dur=0.811135, exclusion.robots;dur=0.029510, exclusion.robots.policy;dur=0.014286, esindex;dur=0.012387, cdx.remote;dur=133.856907, LoadShardBlock;dur=339.950567, PetaboxLoader3.datanode;dur=126.129892, PetaboxLoader3.resolve;dur=204.252083, load_resource;dur=194.417790
x-app-server: wwwb-app210
x-ts: 200
x-tr: 711
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
accept-ranges: bytes
ActiveState Code: Python recipes https://code.activestate.com/recipes/langs/python/ 2009-04-19T00:43:01Z Recently added Python recipes Calculations with error propagation, and semi-formal expressions (Python)
2009-04-19T00:43:01Z Eric O. LEBIGOT https://ActiveState%20Code/recipes/users/2672032/ https://code.activestate.com/recipes/576721/
<p style="color: grey">
Python
recipe 576721
by <a href="/recipes/users/2672032/">Eric O. LEBIGOT</a>
(<a href="/recipes/tags/calculus/">calculus</a>, <a href="/recipes/tags/error propagation/">error propagation</a>, <a href="/recipes/tags/expressions/">expressions</a>, <a href="/recipes/tags/formal calculations/">formal calculations</a>, <a href="/recipes/tags/lazy evaluation/">lazy evaluation</a>, <a href="/recipes/tags/uncertainties/">uncertainties</a>).
Revision 11.
</p>
<p>Module for performing calculations with error propagation, including when there are correlations between parts of an expression (for instance, the error on "x-x" is strictly zero). Basic mathematical operations (addition, etc.), as well as <em>operations defined in the math module</em> and logical operations (<, >, etc.), can be used.</p>
<p>Most code written for floats should work with the numbers with uncertainty defined here. A point to be kept in mind is that expressions that return a number, when used with floats, generally return a "semi-formal expression" object, which behaves very much like a float. These objects have properties that go beyond those of floats: their nominal (central) value <em>and error</em> can be accessed (with the "nominal_value" and "error" attributes); they can be printed in a legible format ("3.14 +- 0.01"); they can also be used in additional formulas written for floats; they can be also differentiated (derivative_value() method); they can also be dynamically calculated (if a variable of type NumberWithUncert is changed, the value of expressions that use it can be recalculated).</p>
<p>The module also contains a class that represents non-evaluated mathematical expressions. This class is used for performing the differentiation required by the error propagation calculation, but can be used on its own, for manipulating "semi-formal" expressions built from Python statements.</p>
lazy property (Python)
2009-04-16T15:42:01Z Sridhar Ratnakumar https://ActiveState%20Code/recipes/users/4169511/ https://code.activestate.com/recipes/576720/
<p style="color: grey">
Python
recipe 576720
by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a>
(<a href="/recipes/tags/evaluation/">evaluation</a>, <a href="/recipes/tags/lazy/">lazy</a>, <a href="/recipes/tags/lazy evaluation/">lazy evaluation</a>).
Revision 5.
</p>
<p>Python does not have lazy evaluation syntax features built-in, but fortunately decorators can be used with new-style classes to emulate such a feature. There are cases where one wants <code>foo.property</code> to return the actual property whose calculation takes significant amount of time.</p>
<p>This recipe adapts the existing <code>property</code> to provide a <code>lazypropery</code> decorator that does this.</p>
<p>See the first comment below for an example usage.</p>
Flattened List (Python)
2009-04-14T12:18:51Z marlonamor https://ActiveState%20Code/recipes/users/4169863/ https://code.activestate.com/recipes/576719/
<p style="color: grey">
Python
recipe 576719
by <a href="/recipes/users/4169863/">marlonamor</a>
(<a href="/recipes/tags/flat/">flat</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/itertools/">itertools</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/nested/">nested</a>).
</p>
<p>This flattenizes any nested level list. I couln't find this in itertools module so I wrote it. Python 3 may be required.</p>
Homogeneous list (Python)
2009-04-14T12:09:19Z marlonamor https://ActiveState%20Code/recipes/users/4169863/ https://code.activestate.com/recipes/576718/
<p style="color: grey">
Python
recipe 576718
by <a href="/recipes/users/4169863/">marlonamor</a>
(<a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/type/">type</a>).
</p>
<p>This is a little code for making a list that can have only items from a list of types</p>
PDF a Directory of Images using Reportlab (Python)
2009-04-12T08:35:10Z andrew.canit https://ActiveState%20Code/recipes/users/4169843/ https://code.activestate.com/recipes/576717/
<p style="color: grey">
Python
recipe 576717
by <a href="/recipes/users/4169843/">andrew.canit</a>
(<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/PDF/">PDF</a>).
</p>
<p>Walk through a directory PDFing Images</p>
Create SHA Hashes of a Directory (Python)
2009-04-14T08:10:26Z andrew.canit https://ActiveState%20Code/recipes/users/4169843/ https://code.activestate.com/recipes/576716/
<p style="color: grey">
Python
recipe 576716
by <a href="/recipes/users/4169843/">andrew.canit</a>
(<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/Hash/">Hash</a>, <a href="/recipes/tags/security/">security</a>, <a href="/recipes/tags/SHA/">SHA</a>).
Revision 2.
</p>
<p>Walk through a Directory creating SHA Hashes of each file path</p>
REAL case insensitive string replace (Python)
2009-04-09T15:03:42Z Jonas Haag https://ActiveState%20Code/recipes/users/4169206/ https://code.activestate.com/recipes/576715/
<p style="color: grey">
Python
recipe 576715
by <a href="/recipes/users/4169206/">Jonas Haag</a>
(<a href="/recipes/tags/case/">case</a>, <a href="/recipes/tags/case insensitive/">case insensitive</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/replace/">replace</a>, <a href="/recipes/tags/str/">str</a>).
</p>
<p>REAL case insensitive version of <code>str.replace</code> that keeps the letter case of the original expression (Doesn't only replace <code>Foo</code> and <code>foo</code> to <code>...foo...</code> but to <code>...Foo..</code> and <code>...foo...</code>).</p>
Extract a compressed file (Python)
2009-04-09T08:19:34Z Sridhar Ratnakumar https://ActiveState%20Code/recipes/users/4169511/ https://code.activestate.com/recipes/576714/
<p style="color: grey">
Python
recipe 576714
by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a>
.
Revision 2.
</p>
<p>This recipe can be used to extract any zip or tar.gz/tar.bz2 file.</p>
Unique lines from a text file, case sensitive or insensitive (Python)
2009-04-05T19:58:50Z nick https://ActiveState%20Code/recipes/users/4169647/ https://code.activestate.com/recipes/576713/
<p style="color: grey">
Python
recipe 576713
by <a href="/recipes/users/4169647/">nick</a>
(<a href="/recipes/tags/uniq/">uniq</a>, <a href="/recipes/tags/unique lines/">unique lines</a>).
</p>
<p>Spits out sorted, deduplicated lines.</p>
Handling ties for top largest/smallest elements (Python)
2009-04-07T18:57:35Z George Sakkis https://ActiveState%20Code/recipes/users/2591466/ https://code.activestate.com/recipes/576712/
<p style="color: grey">
Python
recipe 576712
by <a href="/recipes/users/2591466/">George Sakkis</a>
(<a href="/recipes/tags/heapq/">heapq</a>, <a href="/recipes/tags/largest/">largest</a>, <a href="/recipes/tags/smallest/">smallest</a>, <a href="/recipes/tags/top/">top</a>).
Revision 8.
</p>
<p>The heapq module provides efficient functions for getting the top-N smallest and
largest elements of an iterable. A caveat of these functions is that if there
are ties (i.e. equal elements with respect to the comparison key), some elements
may end up in the returned top-N list while some equal others may not:</p>
<pre><code>>>> nsmallest(3, [4,3,-2,-3,2], key=abs)
[-2, 2, 3]
</code></pre>
<p>Although 3 and -3 are equal with respect to the key function, only one of them
is chosen to be returned. For several applications, an all-or-nothing approach
with respect to ties is preferable or even required.</p>
<p>A new optional boolean parameter 'ties' is proposed to accomodate these cases.
If ties=True and the iterable contains more than N elements, the length of the
returned sorted list can be lower than N if not all ties at the last position
can fit in the list:</p>
<pre><code>>>> nsmallest(3, [4,3,-2,-3,2], key=abs, ties=True)
[-2, 2]
</code></pre>
Yet another enum for Python (Python)
2009-04-03T12:02:33Z Antonio Cuni https://ActiveState%20Code/recipes/users/4169762/ https://code.activestate.com/recipes/576711/
<p style="color: grey">
Python
recipe 576711
by <a href="/recipes/users/4169762/">Antonio Cuni</a>
(<a href="/recipes/tags/enum/">enum</a>).
</p>
<p>There are plenty of ways to declare C-like enums in Python. This one tries to be minimalistic and with a nice syntax, (ab)using decorators.</p>
<p>The code is also available here:
<a href="https://codespeak.net/svn/user/antocuni/hack/enum.py" rel="nofollow">https://codespeak.net/svn/user/antocuni/hack/enum.py</a></p>
Multi-Regex: Single pass replace of multiple regexes (Python)
2009-04-03T13:38:39Z Michael Palmer https://ActiveState%20Code/recipes/users/1827292/ https://code.activestate.com/recipes/576710/
<p style="color: grey">
Python
recipe 576710
by <a href="/recipes/users/1827292/">Michael Palmer</a>
(<a href="/recipes/tags/Regular expressions/">Regular expressions</a>, <a href="/recipes/tags/string substitution/">string substitution</a>).
Revision 5.
</p>
<p>Not really - all regexes first get combined into a single big disjunction. Then, for each match, the matching sub-regex is determined from a group name and the match object dispatched to a corresponding method, or simply replaced by a string. </p>
Parallel map (Python)
2009-04-02T19:41:10Z Miki Tebeka https://ActiveState%20Code/recipes/users/4086267/ https://code.activestate.com/recipes/576709/
<p style="color: grey">
Python
recipe 576709
by <a href="/recipes/users/4086267/">Miki Tebeka</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/map/">map</a>, <a href="/recipes/tags/parallel/">parallel</a>).
Revision 3.
</p>
<p>Implementation of parallel map (processes).</p>
<p>This is a Unix only version.</p>
DVM_Versus_CAPM (Python)
2009-04-01T04:46:55Z Fouad Teniou https://ActiveState%20Code/recipes/users/4155345/ https://code.activestate.com/recipes/576708/
<p style="color: grey">
Python
recipe 576708
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/Corporate_Finance/">Corporate_Finance</a>, <a href="/recipes/tags/Financial_Management/">Financial_Management</a>).
Revision 3.
</p>
<p>Cost of equity could be found using my program DVM_Versus_CAPM by either methods, the DVM ( Dividend Valuation Model ) or the CAPM ( Capital asset pricing model ).
However, value of the share (Company value) could also be found using my program, if the cost of equity Ke is known, whether assuming a constant dividend where Po = D/Ke or a constant growth g where Po = Do(1+g)/Ke-g.
Though, the growth rate g is estimated in two different ways, by using the extrapolating growth formula, based on the past dividend history or by applying the Gordon’s growth model (g = r x b).
Projects undertaken by firms will have different risk profiles, and so is the company return required, since it reflect this risk, thus, the DVM model assumptions conflict, and yet the DVM high sensitivity to these assumptions.
Nevertheless, using the CAPM (Ke = Rf + Beta(Rm - Rf), the investors will require different rates of return for different projects depending of the risk of each project. Rf is the risk free rate, ( Rm - Rf) is the average risk premium, and Beta is the systematic risk of investment.
Beta of the share could be measured or obtained from the commercial information suppliers such as Datastream, and the more volatile the business the higher is Beta.
My program DVM_Versus_CAPM will be of a value to ACCA’s students and also to students of Corporate Finance.</p>
Long period random number generator (Python)
2009-04-01T10:53:27Z Raymond Hettinger https://ActiveState%20Code/recipes/users/178123/ https://code.activestate.com/recipes/576707/
<p style="color: grey">
Python
recipe 576707
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
.
Revision 12.
</p>
<p>Implements a complementary-multiply-with-carry psuedo-random-number-generator. Period is 3636507990 * 2 ** 43487 (approximately 10 ** 13101).</p>
Serve static web content from within a gzipped tarball to save space using CherryPy (Python)
2009-03-31T18:24:06Z Dan McDougall https://ActiveState%20Code/recipes/users/4169722/ https://code.activestate.com/recipes/576706/
<p style="color: grey">
Python
recipe 576706
by <a href="/recipes/users/4169722/">Dan McDougall</a>
(<a href="/recipes/tags/cherrypy/">cherrypy</a>, <a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/embedded/">embedded</a>, <a href="/recipes/tags/gzip/">gzip</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/routes/">routes</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/web server/">web server</a>).
</p>
<p>This code lets you store all of your static website content inside a gzipped tarball while transparently serving it to HTTP clients on-demand. Perfect for embedded systems where space is limited.</p>
pyGTK threading (Python)
2009-04-01T07:07:56Z oohay_email2004 https://ActiveState%20Code/recipes/users/4169723/ https://code.activestate.com/recipes/576705/
<p style="color: grey">
Python
recipe 576705
by <a href="/recipes/users/4169723/">oohay_email2004</a>
(<a href="/recipes/tags/pygtk/">pygtk</a>, <a href="/recipes/tags/threading/">threading</a>).
Revision 2.
</p>
<p>This is my first successful attempt at threading in pyGTK.</p>
<p>Suggestions please.</p>
Python code minifier (Python)
2009-04-14T17:16:56Z Dan McDougall https://ActiveState%20Code/recipes/users/4169722/ https://code.activestate.com/recipes/576704/
<p style="color: grey">
Python
recipe 576704
by <a href="/recipes/users/4169722/">Dan McDougall</a>
(<a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/embedded/">embedded</a>, <a href="/recipes/tags/minify/">minify</a>, <a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/regex/">regex</a>).
Revision 11.
</p>
<p>Python Minifier: Reduces the size of Python code for use on embedded platforms. Performs the following:</p>
<ol>
<li>Removes docstrings.</li>
<li>Removes comments.</li>
<li>Minimizes code indentation.</li>
<li>Joins multiline pairs of parentheses, braces, and brackets (and removes extraneous whitespace within).</li>
<li>Preserves shebangs and encoding info (e.g. "# -<em>- coding: utf-8 -</em>-")</li>
</ol>
xzip - Iterative zip function for very large collections (Python)
2009-03-30T14:54:40Z Tucker Beck https://ActiveState%20Code/recipes/users/4169378/ https://code.activestate.com/recipes/576703/
<p style="color: grey">
Python
recipe 576703
by <a href="/recipes/users/4169378/">Tucker Beck</a>
(<a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/iterative zip/">iterative zip</a>, <a href="/recipes/tags/zip/">zip</a>).
</p>
<p>The xzip function provides the same functionality as zip (python builtin), but utilizes a generator list comprehension so that zipped collections can be accessed iteratively.</p>
<p>Example:
for t in xzip( xrange( 1000000 ), xrange( 1000000, 2000000, 1 ), xrange( 888,100000000, 1 ):
print t</p>
<p>This Will begin to produce output immediately, because the collections are zipped iteratively
The output of this code is exactly equivalent to:</p>
<p>for t in zip( xrange( 1000000 ), xrange( 1000000, 2000000, 1 ), xrange( 888,100000000, 1 ):
print t</p>
<p>However, the second block (using zip) must first build the zipped collection entirely before the
for loop can iterate over it. This could take a long time.</p>
<p>Note, I used xrange here so that we don't have to wait for python to build the initial lists.
The xzip function would probably show its usefulness most if one had several huge collections that
needed to be combined iteratively.</p>
<p>I developed this function to zip long lists ( >100000 ) of vertex triples with color triples in a volume
visualizer.</p>
Pattern Matching in Python (Python)
2009-03-29T14:20:37Z forgot https://ActiveState%20Code/recipes/users/4169688/ https://code.activestate.com/recipes/576702/
<p style="color: grey">
Python
recipe 576702
by <a href="/recipes/users/4169688/">forgot</a>
.
Revision 2.
</p>
<p>It's a combine of patmatch/namedtuple/enum</p>