CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Tue, 15 Jul 2025 20:37:14 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20090619214807
location: https://web.archive.org/web/20090619214807/https://code.activestate.com/feeds/langs/python/
server-timing: captures_list;dur=0.905121, exclusion.robots;dur=0.030212, exclusion.robots.policy;dur=0.013389, esindex;dur=0.020087, cdx.remote;dur=45.729253, LoadShardBlock;dur=842.472071, PetaboxLoader3.datanode;dur=143.051179, PetaboxLoader3.resolve;dur=617.280921
x-app-server: wwwb-app215
x-ts: 302
x-tr: 1242
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app215; 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: Tue, 15 Jul 2025 20:37:15 GMT
content-type: application/atom+xml
content-length: 24263
x-archive-orig-date: Fri, 19 Jun 2009 21:42:33 GMT
x-archive-orig-server: Apache/2.2.3 (CentOS)
x-archive-orig-content-length: 24263
x-archive-orig-expires: Fri, 19 Jun 2009 21:51:35 GMT
x-archive-orig-vary: Cookie
x-archive-orig-last-modified: Fri, 19 Jun 2009 21:41:35 GMT
x-archive-orig-etag: c844fa9804153fa58ff514c800290efd
x-archive-orig-cache-control: max-age=600
x-archive-orig-age: 287
x-archive-orig-via: 1.0 box18.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: Fri, 19 Jun 2009 21:48:07 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="Fri, 19 Jun 2009 15:51:51 GMT", ; rel="memento"; datetime="Fri, 19 Jun 2009 21:48:07 GMT", ; rel="next memento"; datetime="Sat, 22 Aug 2009 18:35:50 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_10_20090619201201_crawl100-c/52_10_20090619214639_crawl103.arc.gz
server-timing: captures_list;dur=0.547985, exclusion.robots;dur=0.018476, exclusion.robots.policy;dur=0.009140, esindex;dur=0.009544, cdx.remote;dur=17.146688, LoadShardBlock;dur=441.601165, PetaboxLoader3.datanode;dur=221.730096, PetaboxLoader3.resolve;dur=334.542792, load_resource;dur=160.873972
x-app-server: wwwb-app215
x-ts: 200
x-tr: 656
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-06-19T03:41:42Z Recently added Python recipes CommentEditor: HTML editor for online comments (Python)
2009-06-17T12:10:55Z Jack Trainor https://ActiveState%20Code/recipes/users/4076953/ https://code.activestate.com/recipes/576814/
<p style="color: grey">
Python
recipe 576814
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/wxWidgets/">wxWidgets</a>).
Revision 3.
</p>
<p>Edit online comments with easy addition of HTML tags for bold, italics, underlining, blockquote and anchored links. Then check your work with the preview feature.</p>
<p>Requires wxWidgets.</p>
Generate HTML syntax-highlighted listings for any file using pygments (Python)
2009-06-19T03:41:42Z ccpizza https://ActiveState%20Code/recipes/users/4170754/ https://code.activestate.com/recipes/576812/
<p style="color: grey">
Python
recipe 576812
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/pretty-printer/">pretty-printer</a>, <a href="/recipes/tags/pygments/">pygments</a>, <a href="/recipes/tags/syntax highlighter/">syntax highlighter</a>).
Revision 5.
</p>
<p>Generates HTML highlighted code listings for source code files in any language known to
pygments. For a list of supported formats see <a href="https://pygments.org/languages" rel="nofollow">https://pygments.org/languages</a></p>
<p>Make sure you have <a href="https://pygments.org">pygments</a> is installed. Try <code>easy_install pygments</code>.</p>
Rename MP3 files from ID3 tags (Python)
2009-06-19T03:38:26Z ccpizza https://ActiveState%20Code/recipes/users/4170754/ https://code.activestate.com/recipes/576811/
<p style="color: grey">
Python
recipe 576811
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/ID3/">ID3</a>, <a href="/recipes/tags/MP3/">MP3</a>, <a href="/recipes/tags/rename/">rename</a>).
Revision 3.
</p>
<p>Rename MP3 files in the current folder according to ID3 tags. This is based on Ned Batchelder's id3reader class. All I did was to add the code to the <code>__main__</code> test method.</p>
<ul>
<li>When run without arguments, the script renames the files in the current folder. A directory can be specified explicitly as first argument.</li>
<li>The files do not need to necessarily have the <code>MP3</code> extension.</li>
<li>To also create directories based on album use the <code>-d</code> switch.</li>
<li>Does not work with other file types, such as OGG, M4A, MP4, etc.</li>
<li>This is a quick hack. If you need more power, use mutagen, picard, mp3tag or something similar.</li>
</ul>
Copy files over SSH using paramiko (Python)
2009-06-19T03:22:29Z ccpizza https://ActiveState%20Code/recipes/users/4170754/ https://code.activestate.com/recipes/576810/
<p style="color: grey">
Python
recipe 576810
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/paramiko/">paramiko</a>, <a href="/recipes/tags/SCP/">SCP</a>, <a href="/recipes/tags/SSH/">SSH</a>).
Revision 17.
</p>
<p>This script copies files in unattended mode over SSH using a glob pattern. It uses the <a href="https://www.lag.net/paramiko/">paramiko</a> module behind the scenes. It operates as an actual SSH client, and does <em>not</em> rely on any command line utilities, such as <code>scp</code>.</p>
<p>It first tries to connect using a key from a private key file or from an SSH agent. If RSA authentication fails, it will try to authenticate with a password, if passwords are allowed on the SSH server.
Assumes the <code>rsa_private_key</code> was generated with an empty passphrase.</p>
<p>On most unix/linux systems paramiko can be installed with <code>easy_install paramiko</code> from a console.</p>
<p>Win32 binary installers are available from <a href="https://bialix.com/python/" rel="nofollow">https://bialix.com/python/</a></p>
Python reader for SPSS .por files (Python)
2009-06-15T15:37:39Z wouter https://ActiveState%20Code/recipes/users/4170747/ https://code.activestate.com/recipes/576809/
<p style="color: grey">
Python
recipe 576809
by <a href="/recipes/users/4170747/">wouter</a>
(<a href="/recipes/tags/por/">por</a>, <a href="/recipes/tags/portable/">portable</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reader/">reader</a>, <a href="/recipes/tags/spp/">spp</a>, <a href="/recipes/tags/value labels/">value labels</a>).
</p>
<p>SPSS can output ASCII .por files that include variable definitions (labels, value labels) and data. These files are useful to be able to read but strange enough I couldn't find any documentation anywhere.</p>
<p>I've reverse engineered the format so that it works for the (fairly complex) files I need to open, so maybe it is of some use for other people interfacing SPSS with python. </p>
<p>This code is placed in the public domain as far as allowed by law, parts (if any) that cannot be relased in the public domain are irrevocably licensed to all readers under the Creative Commons license without restrictions ... but if you improve it it would be great if you could share it. The code uses a base N decoder plucked from the web somewhere (can't find it) that was also public domain.</p>
<p>-- wouter (wouter@vanatteveldt.com)</p>
@statemethod (Python)
2009-06-15T13:46:39Z Charlie Nolan https://ActiveState%20Code/recipes/users/4170745/ https://code.activestate.com/recipes/576808/
<p style="color: grey">
Python
recipe 576808
by <a href="/recipes/users/4170745/">Charlie Nolan</a>
(<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/state pattern/">state pattern</a>).
</p>
<p>Decorator for use with objects following the <a href="https://en.wikipedia.org/wiki/State_pattern">state pattern</a>.</p>
Send Email (Python)
2009-06-14T06:44:50Z sfwgeek https://ActiveState%20Code/recipes/users/4170734/ https://code.activestate.com/recipes/576807/
<p style="color: grey">
Python
recipe 576807
by <a href="/recipes/users/4170734/">sfwgeek</a>
(<a href="/recipes/tags/CLI/">CLI</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/OptionParser/">OptionParser</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/send/">send</a>, <a href="/recipes/tags/smtplib/">smtplib</a>).
Revision 3.
</p>
<p>A command line interface (CLI) program to send email.</p>
Regular Expression for generic sequences of symbols (Python)
2009-06-13T09:51:38Z Emanuele Ruffaldi https://ActiveState%20Code/recipes/users/4170726/ https://code.activestate.com/recipes/576806/
<p style="color: grey">
Python
recipe 576806
by <a href="/recipes/users/4170726/">Emanuele Ruffaldi</a>
(<a href="/recipes/tags/adt/">adt</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/Regular expressions/">Regular expressions</a>, <a href="/recipes/tags/sequence/">sequence</a>).
Revision 2.
</p>
<p>Python regular expression are very powerful and efficient and they can be applied to the recognition of different types of sequences. This recipe shows how to match sequences of generic symbol set with the power of regular expression. The code uses a mapping from every entity into a character. The mapping is used both at level of sequence and in the compilation of the regular expression. When the symbol set is small it is possible to efficiently use 8 bit strings instead of full unicode.</p>
Pastebin Upload (Python)
2009-06-12T20:58:18Z Logic Kills https://ActiveState%20Code/recipes/users/4168055/ https://code.activestate.com/recipes/576805/
<p style="color: grey">
Python
recipe 576805
by <a href="/recipes/users/4168055/">Logic Kills</a>
(<a href="/recipes/tags/code/">code</a>, <a href="/recipes/tags/post/">post</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/source/">source</a>, <a href="/recipes/tags/urllib2/">urllib2</a>).
</p>
<p>A little script I made for some buddies and I. We are constantly collaborating on code. This scrips takes a source code file as it's parameter and uploads it to <a href="https://pastebin.com" rel="nofollow">https://pastebin.com</a> or any sub domain of pastebin.
I integrated it with the righ click window in windows. Without that integration the script wouldn't be as cool!
Hope others find it useful.</p>
Find the oldest (or yougest) of a list of files (Python)
2009-06-10T16:08:13Z Micah Elliott https://ActiveState%20Code/recipes/users/2649403/ https://code.activestate.com/recipes/576804/
<p style="color: grey">
Python
recipe 576804
by <a href="/recipes/users/2649403/">Micah Elliott</a>
(<a href="/recipes/tags/age/">age</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/find/">find</a>, <a href="/recipes/tags/queue/">queue</a>).
</p>
<p>Sometimes you need to perform an operation on the oldest of a set of files. Using <em>get_oldest_file</em> you could implement an age-based priority queue that processes files from oldest to newest. The list of files you pass in may be from a <em>glob</em> of a single directory or some more elaborate search routine.</p>
Run-Time Configurable Logging (Python)
2009-06-10T05:46:19Z Alex Omoto https://ActiveState%20Code/recipes/users/4170524/ https://code.activestate.com/recipes/576803/
<p style="color: grey">
Python
recipe 576803
by <a href="/recipes/users/4170524/">Alex Omoto</a>
(<a href="/recipes/tags/logging/">logging</a>).
Revision 4.
</p>
<p>The following Python code is an extension to the logging module by allowing logging configuration at run-time. </p>
Reversed Ranges (Python)
2009-06-10T21:25:50Z Tal Einat https://ActiveState%20Code/recipes/users/2892534/ https://code.activestate.com/recipes/576801/
<p style="color: grey">
Python
recipe 576801
by <a href="/recipes/users/2892534/">Tal Einat</a>
(<a href="/recipes/tags/iteration/">iteration</a>, <a href="/recipes/tags/range/">range</a>, <a href="/recipes/tags/reverse/">reverse</a>).
Revision 15.
</p>
<p>A simple function for efficiently iterating over ranges in reverse.</p>
<p>This is equivalent to reversed(range(...)) but somewhat more efficient.</p>
Convert text/enriched MIME to text/html (Python)
2009-06-09T15:08:40Z Jack Trainor https://ActiveState%20Code/recipes/users/4076953/ https://code.activestate.com/recipes/576800/
<p style="color: grey">
Python
recipe 576800
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/MIME/">MIME</a>, <a href="/recipes/tags/text/enriched/">text/enriched</a>).
</p>
<p>Converts text stream in text/enriched MIME format from file or stdin to text/html output to file or stdout.</p>
tarfile.extractall with read access (Python)
2009-06-04T15:48:17Z Sridhar Ratnakumar https://ActiveState%20Code/recipes/users/4169511/ https://code.activestate.com/recipes/576797/
<p style="color: grey">
Python
recipe 576797
by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a>
(<a href="/recipes/tags/tarfile/">tarfile</a>).
</p>
<p>Some tarballs have u-x set on directories .. this makes the program fail due to permissions. See <a href="https://bugs.python.org/issue6196" rel="nofollow">https://bugs.python.org/issue6196</a></p>
Python Syntax Highlighting in OpenOffice Impress (Python)
2009-06-04T12:24:04Z Bryan Cole https://ActiveState%20Code/recipes/users/4170610/ https://code.activestate.com/recipes/576796/
<p style="color: grey">
Python
recipe 576796
by <a href="/recipes/users/4170610/">Bryan Cole</a>
(<a href="/recipes/tags/highlighting/">highlighting</a>, <a href="/recipes/tags/Impress/">Impress</a>, <a href="/recipes/tags/OpenOffice/">OpenOffice</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/syntax/">syntax</a>).
</p>
<p>Applies python syntax highlighting to all the TextShapes (i.e. text boxes) in an OpenOffice document with the "code" graphic style applied. Typical usage is for highlighting code snippets in an Impress presentation. I have the "HighlightPython" function assigned to a menu item in my Tools menu for easy access. </p>
Partitioning a sequence (Python)
2009-06-03T20:57:42Z Raymond Hettinger https://ActiveState%20Code/recipes/users/178123/ https://code.activestate.com/recipes/576795/
<p style="color: grey">
Python
recipe 576795
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
.
Revision 2.
</p>
<p>Distinct partitions of a sequence.</p>
Utility Mill Support Example (Python)
2009-06-03T14:36:25Z Stephen Chappell https://ActiveState%20Code/recipes/users/2608421/ https://code.activestate.com/recipes/576793/
<p style="color: grey">
Python
recipe 576793
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/Python 3.0/">Python 3.0</a>, <a href="/recipes/tags/RPC/">RPC</a>, <a href="/recipes/tags/testing/">testing</a>, <a href="/recipes/tags/Utility Mill/">Utility Mill</a>).
</p>
<p>For those of you wondering how use "utility_mill" (my previous recipe), check out "hard_test()" and "soft_test()" in this example usage. The code in the lower sections generates test data and is only useful if trying to understand the "expressions" recipe initially ported from C#. The hard test shows how easy it is to execute a utility that you know the name of. The most recent version is used, but this can be inefficient. The soft test runs the same utility once a minute but only updates the version once an hour. This can saves the Utility Mill some extra work that may not be necessary.</p>
Polar-to-rectangular conversions using CORDIC (Python)
2009-06-03T14:34:58Z Raymond Hettinger https://ActiveState%20Code/recipes/users/178123/ https://code.activestate.com/recipes/576792/
<p style="color: grey">
Python
recipe 576792
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
.
</p>
<p>Demonstrate CORDIC algorithm for computing coordinate conversions using only adds and shifts (plus one multiply in the outer loop).</p>
Utility Mill Support (Python)
2009-06-03T14:18:24Z Stephen Chappell https://ActiveState%20Code/recipes/users/2608421/ https://code.activestate.com/recipes/576791/
<p style="color: grey">
Python
recipe 576791
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/Python 3.0/">Python 3.0</a>, <a href="/recipes/tags/RPC/">RPC</a>, <a href="/recipes/tags/testing/">testing</a>, <a href="/recipes/tags/Utility Mill/">Utility Mill</a>).
Revision 2.
</p>
<p>Have you ever published a recipe to <a href="https://UtilityMill.com" rel="nofollow">https://UtilityMill.com</a> and then wished that you could remotely execute your program? Now that is easy to do with the following supporting library! Running the latest version of your program is easy with the "run_latest(name, query)" command and requires no knowledge of UM's API -- just supply the program's name and keyword arguments that it requires for execution. "utility_mill" is easy to use and can be customized with access to more specific commands available to you. You do not need to know the latest version number? Just use "get_results(name, version, query)" instead to save a call to the server!</p>
Expression Evaluator (Python)
2009-06-02T23:57:44Z Stephen Chappell https://ActiveState%20Code/recipes/users/2608421/ https://code.activestate.com/recipes/576790/
<p style="color: grey">
Python
recipe 576790
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/evaluation/">evaluation</a>, <a href="/recipes/tags/expressions/">expressions</a>, <a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/Python 3.0/">Python 3.0</a>).
Revision 4.
</p>
<p>After reading a portion of the book "The C# Programming Language: Third Edition," I found a section in the introduction that introduced abstract classes and methods that involved an example that included the concept of expression trees. The code was easy to implement since it just had to be copied out of the book. After playing around with the program a little and extending it, I thought that it would be fun to write a program in C# that could (interactively) evaluate expressions and display the results. Not knowing C# quite as well as Python led to the following program written and tested in Python 3.0 (not sure about previous languages).</p>
<p>The first section of the code includes port of the program from the aforementioned book along with extra code that allows for further features not originally included in the C# version. Those sections are clearly marked as being new code written by yours truly. The second area of the program has six functions that are profusely documented so as to explain how they go about parsing and processing expressions entered for evaluation. For those wishing to use the code, the "run" function should be all that you need. The final part of the module contains a test program that can be used to check the validity of the how well the program works.</p>
<p>The parser is not very complicated and will except expressions that are both normal to Python and completely illegal in Python. The main features are its ability to (1) identify simple assignment and mathematical operations, (2) identify constant floating point numbers, and (3) identify variables that would otherwise have no other meaning to the program. A limited number of error messages are given when appropriate but may leave one guessing what the problem really is. Mathematical operations are evaluated from left to right without regards to precedence, and assignment statements are evaluated from right to left.</p>