Archive for the ‘Python’ Category

My affair with Zope3

February 24, 2008

When Martijn Faassen introduced me to Zope3 in December 2004, something happened. I fell for her logic, her view on the future. Her looks were promising. We quickly partnered in a small project I was working on.

Then things started to get messy. Evenings of joy turned into evenings of long, frustrating conversations. She just wouldn’t dance with me anymore. She complained about my lack of understanding.

Last week I received Philipp’s updated Zope counseling guide. A fresh impulse to give our relation a second chance. Hopefully Philipp will assist me in understanding her better.

On first sight things seem promising. Zope3 let go some of her complexness and grew a bit more mature. Let’s see if we can get to dancing again!

You can become my colleague

February 28, 2007

sfk logoThe company I work for (SFK) is looking for a full-time Data Warehouse Developer (m/f).

You should know how to program OO, preferably in Python. Be keen on Linux and open source in general. Know how to handle large databases. Your dutch should be fluent (sorry about that).

They’re nice to me.

What’s the catch? You’ll end up working closely with me :)

OLPC: Python for transparency

January 6, 2007

At the end of One Laptop per Childs Human Interface Guidelines / Design Fundamentals:

Transparency

OLPC also hopes to encourage the children […] to explore the technology under the surface. […] a view source key has been added to the laptop keyboards, providing them with […] the code that enables the activities that they use from day to day.

[…] OLPC has written much of what can be in Python, a scripting language, to enable children to view the source code.

Their SVG page reads this notable development guideline:

Authors of OLPC content should try to use SVG wherever possible. Only use bitmaps such as JPEG or PNG where it is not possible to use SVG.

As a sidenote, their Python page pointed me to Movable Python. This product enables you to run Python programs from your USB memory stick, without installing software on the PC you’re using. Sounds like something I will be using.

Five essential phone-screen questions

January 4, 2007

For just five interview questions, it surely ended up as a long read. Nevertheless worth the read:

The Five Essential Phone-Screen Questions — Steve Yegge

I just might translate some of his examples to Python:

Example 1: Write a function to reverse a string

def reverse(text):
....result = list(text)
....return ''.join(result[::-1]) 

or, just

def reverse(text):
....return text[::-1]

Example 2: Write function to compute Nth fibonacci number

def fib(n):
...."""Calculate fibonacci value for given n
....Doctests:
....>>> [fib(i) for i in xrange(0, 10)
....[0, 1, 1, 2, 3, 5, 8, 12, 21, 34, 55]
...."""
....if n 

Example 3: Print out the grade-school multiplication table up to 12x12

def multiplication_table(n):
...."""Generate an n*n multiplication table
....>>> len(multiplication_table(10))
....10
....>>> len(multiplication_table(5)[0])
....5
...."""
....# Create matrix
....table = [[x*y for x in xrange(1, n+1)] for y in xrange(1, n+1)]
....return table

def print_matrix(matrix):
...."""Expects a list of lists """
....for row in matrix:
....|...print "%4d" * len(row) % tuple(row)

if __name__ == "__main__":
...."""Run actual program code """
....print_matrix(multiplication_table(12))

Example 4: Write a function that sums up integers from a text file, one int per line

def sum_file(filename):
...."""TODO: catch exceptions """
....fp = file(filename)
....try:
....|...numbers = [int(line.strip()) for line in fp]
....finally:
....|...fp.close()
....return sum(numbers)

Example 5: Write function to print the odd numbers from 1 to 99

def print_odds():
....for i in xrange(0, 100, 2):
....|...print i 

Example 6: Find the largest int value in an int array

def largest(sequence):
...."""Find the largest occurrence in a sequence ('array')
....>>> largest([0])
....0
....>>> largest(range(100))
....99
....>>> largest([1, 0, -1])
....1
...."""
....return max(sequence)

Example 7: Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string

def format_rgb(red, green, blue):
...."""Convert integer RGB to hex RGB string
....
....>>> format_rgb(0, 0, 0)
....'000000'
....>>> format_rgb(255, 0, 0)
....'FF0000'
....>>> format_rgb(0, 255, 0)
....'00FF00'
....>>> format_rgb(0, 0, 255)
....'0000FF'
....>>> format_rgb(255, 255, 255)
....'FFFFFF'
...."""
....return "%02X%02X%02X" % (red, green, blue)

Test solutions:

def _test():
...."""Run tests on functions in module """
....import doctest
....doctest.testmod()

Please ignore points and pipes. WordPress can't handle code layout well. Python is white-space sensitive. This is the best I could come up with.

Python and Yahoo

November 20, 2006

If you’re a Python enthusiast and regular Yahoo! user like me, you might find the Yahoo! Python Developer Center interesting.

yahoo developer network

Python package convention

September 5, 2006

Hard to find, but there is a convention for packaging your modules and classes. From Ian Bicking’s presentation, page 18:

MyPackage/

setup.py
ez_setup.py
mypackage/

__init__.py
other_stuff.py
data/

mydata.xml

tests/
docs/

Page 19:

Your “distribution” has a name: MyPackage, not to be confused with your “package”: mypackage. Packages and modules all lower-case by convention.

Page 20:

Documentation and (usually) tests go outside the package, mypackage/ is all that really gets installed. setup.py describes the package

Google Trends: Web Dev II

June 27, 2006

Well, I just discovered a feature on Google Trends that sheds a different light on my previous post on web development techniques. Displaying several trends in one image reveals the relative size of search volumes of specific terms.

As can be seen when comparing ‘zope’, ‘plone’, ‘ruby rails’ and ‘turbogears':

webdev comparisons zope ruby on rails turbogears plone

Somewhat related, ‘mambo’ and ‘joomla':

joomla mambo

Try for yourself.

Python meeting The Hague 2006-06-14

May 30, 2006

Please feel invited to join the next Python Users NL meeting in the Hague on wednesday the 14th of June.

2006-06-14 19.30 – 22.00
Ondernemerscafé, Hooikade 56, Den Haag

Subjects, so far:

  • Dynamic SVG using Python (SVG, JavaScript, CSS)
  • Generating PDF from Zope (DocBook XML, ZPT, XSLT, FO)

I happen to be the organiser, so if you’re proud of something Python-related, let me know and I’ll give you an audience.

Python class pooling

May 17, 2006

I liked JW’s class pooling example at DevLog.nl. Below a rewrite without the global ClassPool and ‘static’ ClassPool.id. Also EAFP in action:

class PooledClass(object):
 'Pools instances by id'
 _pool = {}

 def __new__(cls, id):
  """Creator """
  try:
   return cls._pool[id]
  except KeyError:
   obj = object.__new__(cls)
   cls._pool[id] = obj
   return obj

 def __init__(self, id):
  'Constructor '
  self.id = id

2006-10-09: Changed ‘self’ to ‘cls’ in __new__

Google Trends: Web Dev

May 13, 2006

google trends ruby rails
google trends turbogears
google trends plone
google trends php
google trends zope
Source: Google Trends

It could mean people know Zope well enough, not to look it up every day. It could also mean Zope is losing ground.

Also interesting: Linux, Ubuntu (up) and RedHat (down)


Follow

Get every new post delivered to your Inbox.