26th September 2007
These are all excerpts from the Python documentation.
To synchronously and simultaneously loop over two sequences:
PYTHON:questions = ['name', 'quest', 'favourite colour']
answers = ['Lancelot', 'the holy grail', 'blue']
for q, a in zip(questions, answers):
print 'What is your %s? It is %s.' % (q, a)
To loop over a sequence with both key and value:
Read the rest of this entry »
Posted in Programming, Python | No Comments »
26th September 2007
Sample script (copypasted from Well House Consultants training course):
click the PLAIN TEXT header for copy-pasteable version
PYTHON:#!/usr/local/bin/python
author = {"php":"Rasmus Lerdorf",\
"perl":"Larry Wall",\
"tcl":"John Ousterhout",\
"awk":"Brian Kernighan",\
"java":"James Gosling",\
"parrot":"Simon Cozens",\
"python":"Guido van Rossum"}
langs = author.keys()
langs.sort()
for language in langs:
print language,"is the child of",author[language]
You can also define the Python ksort() function similar to that found in PHP:
Read the rest of this entry »
Posted in Programming, Python | 1 Comment »
7th September 2007
Andy Dustman (used to blog at dustman.net) gave a presentation on Python and MySQL at the MySQL Users Conference 2005, Santa Clara, CA. The presentation is an excellent collection of examples for those who use the MySQLdb Python module.
Read the rest of this entry »
Posted in Links, Notepad, Programming, Python | No Comments »
12th August 2007
To iterate through all the files within the specified directory (folder), with ability to use wildcards (*, ?, and [ ]-style ranges), use the following code snippet:
Read the rest of this entry »
Posted in Programming, Python | 33 Comments »
15th March 2007
Recently I learned about Zope, which is an "open source web application server", primarily written in Python.
Then Django and Turbogears were seen as web-development frameworks akin to Zope. Search revealed an interesting anti-Zope rant at Zope vs Django. Reading until the end, and then following the comments, I came across the comment by Holger Froebe, which is a huge one (probably the longest comment I had ever seen), and represents a detailed explanation with examples of the reasons to use Zope 3. I found that comment to be a really good-written one, so if you are deciding on whether you should use Zope 3 or not, then read the comment here (scroll down or just search for "Holger Froebe").
For convenience and in order to preserve this worhty piece of work from vanishing, below is the 99%-exact copy-paste of that comment.
Read the rest of this entry »
Posted in CMS, Programming, Python, Software, Web | 1 Comment »