Wednesday, September 28, 2005

The aggdraw Module

An AGG-based drawing interface.

The aggdraw module implements the basic WCK 2D Drawing Interface on top of the AGG library. This library supports anti-aliasing and alpha compositing, but is otherwise fully compatible with the WCK renderer.


# draw cross on top of PIL image

d = aggdraw.Draw(im)
p = aggdraw.Pen("black", 0.5)
d.line((0, 0, 500, 500), p)
d.line((0, 500, 500, 0), p)

# draw cross on internal image memory
d = aggdraw.Draw("RGB", (320, 200), "white")
p = aggdraw.Pen("black", 0.5)
d.line((0, 0, 500, 500), p)
d.line((0, 500, 500, 0), p)
s = d.tostring()


IPTCInfo: extract and modify IPTC (metadata) information on images - port of by Josh Carter'

Ever wish you add information to your photos like a caption, the place you took it, the date, and perhaps even keywords and categories? You already can. The International Press Telecommunications Council (IPTC) defines a format for exchanging meta-information in news content, and that includes photographs. You can embed all kinds of information in your images. The trick is putting it to use.

That's where this IPTCInfo Python module comes into play. You can embed information using many programs, including Adobe Photoshop, and IPTCInfo will let your web server -- and other automated server programs -- pull it back out. You can use the information directly in Python programs, export it to XML, or even export SQL statements ready to be fed into a database.

Sunday, September 18, 2005


Wikipedia, who doesn't love it?

Wikipedia, the free encyclopedia that anyone can edit.The English version, started in 2001, currently has 678,276 articles. But check how many it has today, as it steadily grows...
Once you've met it, and know a bit how to use it (Wikipedia derives 66% of it's ttraffic from search engine referrals, and 50% of that traffic comes from Google, meaning 33% of all Wikipedia traffic is from Google referals alone (according to Hitwise), you ought to be caught by it. Fancinated, and querying quite a lot of topics, as there is plenty of info on 'quite a few' items. If you look at the statistics page, you can see there are quite a lot of internal links.

Hyperlinks aren't bad.

Hypertext is good..

We see this in blogging, wiki's, manuals etc.
One thing you get from using links, and by visiting them, is that you can access related material. This might be more detailed info, of something completely different but from the same family. Like this plant page, or as a perfect example, the disambiguation page for the word "Plant". (I found that page because it was the first link on the plant page - there you have hypertext at work).
By wandering the WorldWideWeb this way (the way of the wiki) you can see the net visualised by a graph (commonly used in the study of complex systems and other interesting topics) (If you like it, take a lookt at NetworkX and graphviz to do some study yourself, or plot some of your own)
One disadvantage of the graph/net/linked structure, is that you can easily get lost in the maze of links... Or get to meet way to many interesting articles to read at a time. Wikipedia ofter does that to me.

Like the other day, someone posted this link, where i found that vegetarians were previously called "Pythagoreans". This has a reference to python the way i see it, though it originally refers to Pythagoras (the father of numbers).
Though i was enjoyed with this discovery at first, as the vegetarian page describes Pythagoras had said:
As long as man continues to be the ruthless destroyer of lower living beings he will never know health or peace. For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love.

Following the link to Pythagoras (because, once again i got curious) i learned:
Another important discovery of this school -- which upset Greek mathematics, as well as the Pythagoreans' own belief that whole numbers and their ratios could account for geometrical properties -- was the incommensurability of the diagonal of a square with its side. This result showed the existence of irrational numbers.

Hmm. Irrational numbers, i never really understood what those were... so, i hit the link... and learned a bit about it:
In mathematics, an irrational number is any real number that is not a rational number, i.e., one that cannot be written as a ratio of two integers, i.e., it is not of the form a/b where a and b are integers and b is not zero. It can readily be shown that the irrational numbers are precisely those numbers whose expansion in any given base (decimal, binary, etc) never ends and never enters a periodic pattern, but no mathematician takes that to be a definition. Almost all real numbers are irrational, in a sense which is defined more precisely below.

But i also learned:
The story goes that Hippasus discovered irrational numbers when trying to represent the square root of 2 as a fraction (proof below). However Pythagoras believed in the absoluteness of numbers, and could not accept the existence of irrational numbers. He could not disprove their existence through logic, but his beliefs would not accept the existence of irrational numbers and so he sentenced Hippasus to death by drowning.

... i found it quite disturbing, that the man i was just getting fond of, had a man killed because of some mathematical theory.. So, he might be a vegetarian, but he definitly wasn't a better man..

And all this, i wouldn't have known, if it weren't for Wikipedia, and all the contributors. So thanks to all of you!

Wednesday, September 14, 2005


EasyGUI is a module for very simple, very easy GUI programming in Python.

Not using callbacks and that kinda stuff, but for plain and simple user querying.

Tuesday, September 13, 2005


The page of pydot, a Python interface to Graphviz's Dot language.

# import pydot
# edges=[(1,2), (1,3), (1,4), (3,4)]
# g=pydot.graph_from_edges(edges)
g.write_jpeg('graph_from_edges_neato.jpg', prog='neato')

Check out the resulting image.

Monday, September 12, 2005

Word breaking in IE

From this page comes the following:
For table cells, nowrap works

In special cases, when the data is in a table cell and it is adequate to prevent all line breaks in it, you can use the nowrap attribute for the td or th element. That attribute is "deprecated", but it is still valid. Note, however, that browsers seem to ignore it, if a fixed width (in pixels) is set for the cell so that the content doesn't fit into that without wrapping.

The nobr markup
It seems that in general the only cure is to use the nonstandard, Netscape-invented (!) nobr markup. It has never been adequately defined, and browsers generally treat it in a command-like fashion: is taken as "disallow line breaks from now on" and says "line breaks allowed from now on". But it is safest to use it as text-level markup only. This should suffice, since we normally would use nobr for short pieces of text only, as in vis-a-vis or -a.


Web Site Test Tools and Site Management Tools

More than 290 tools listed in 12 categories

From Software QA/Test Resource Center

Thursday, September 08, 2005

Vim keybindings for FireFox


Check out how to do it using this article.

gherkin not so fast after all

Darn... tests prove otherwise.

I've tried the test myself. But shortened it a bit.

This is the testcode:
import time

def test(module):
t = time.clock()
s = module.dumps(value)
print module.__name__, 'encode', time.clock() - t, 'seconds', len(s), 'bytes'
t = time.clock()
print module.__name__, 'decode', time.clock() - t, 'seconds'

value = (("this is a record",1,2,1000001,"(08)123123123",
"some more text",22/7.0,
u"some unicode",True,False,None)*50000)
print 'repr(value) length ==',len(`value`)

import encoder, marshal, pickle, cPickle, json, xmlrpclib
value = (("this is a record",1,2,1000001,"(08)123123123",
"some more text",22/7.0,1,0,None)*50000)
print 'without the long, boolean, and unicode. New data length is',
print 'represented:',len(`value`)
olddump = xmlrpclib.dumps
xmlrpclib.dumps = lambda x:olddump(x,allow_none=1)

And these were my (somewhat more readable) results:
repr(value) length == 8800000

encoder encode 2.021 seconds 7450011 bytes
encoder decode 4.957 seconds
marshal encode 26.181 seconds 7000005 bytes
marshal decode 0.395 seconds
pickle encode 4.846 seconds 5300075 bytes
pickle decode 3.305 seconds
cPickle encode 1.125 seconds 5300075 bytes
cPickle decode 0.886 seconds

without the long, boolean, and unicode.
New data length is represented: 5100000
encoder encode 1.580 seconds 4650011 bytes
encoder decode 3.549 seconds
marshal encode 14.779 seconds 5200005 bytes
marshal decode 0.309 seconds
pickle encode 3.875 seconds 2550061 bytes
pickle decode 2.646 seconds
cPickle encode 0.559 seconds 2550061 bytes
cPickle decode 0.456 seconds
json encode 9.118 seconds 4350001 bytes
json decode 38.152 seconds
xmlrpclib encode 5.157 seconds 26500019 bytes
xmlrpclib decode 21.704 seconds

Note how marshel is the fastest for decoding, while cPicklehas the best overall performance.

If anyone is willing to extend this with any other modules. Like repr and unrepr, i surely would appreciate it.


From LGT, home of NanoThreads comes Gherkin:

A gherkin is a simple pickle. It is a simple serialization algorithm, written in Python, which serializes simple python types (including longs and sequence types (and nested structures)) into a size and speed efficient binary string. It has the same API as the marshal module.

import gherkin
value = [1,2,3,"Four","Five",["Six",7],{8:9,10:11},12.131415,(16,[17,18])]
serial = gherkin.dumps(value)
new_value = gherkin.loads(serial)
assert value == new_value

It is used to decode serialized strings from unknown / untrusted sources (network connections) in a safe manner, which pickle and marshal are unable to do. <plug>It is faster than JSON and Pickle, and can often beat marshal in the size and speed competition. It can serialize all simple Python types, which JSON cannot do, and which bencode cannot do.</plug>. It also comes with a nice set of unit tests to prove it's safety.

Faces - for project managers

Bumped into this one. Faces. . With it, you write your planning as a python like program (though with some creative use of python constructs i must say).. Check out the docx, this program appears to be really neat!

What is faces

Faces is a powerful, flexible and free projectmanagment tool.

Faces stands for flexible, automated, calculating, extendible, simulating.

Faces is based on python, an easy to learn and powerful programming language. Projects in faces are simple python programs, which can be edited by the graphical front-end or your favorite text editor. The comfortable auto completion function enables you to input many tasks very fast and restructure them afterwards.

Faces combines the maturity of a shrink-wrapped product with the flexibility of an individual software.

Faces is designed to be easily extendible to custom needs (e.g. adding new custom fields to tasks is a breeze). The whole power of python can easily be used to generate all kinds of output, to change the scheduling behavior or to modify the graphical front-end.

Faces is divided in a class framework and a graphical front-end. Faces project files use the class framework and can act as stand-alone programs. You can use them to generate your reports without the graphical front end. Therefore the report generation process can be automated, for example to update a web-report periodically.

Faces enables you to save snapshots of your projects to track the changes while progressing and compare them to your initial planning.

With faces you your risks can be seized and simulated in different scenarios. It is possible to build and evaluate several planning alternatives.

In faces you are able to use a common resource database and to balance your resources simultaneously over multiple projects. It is also possible to generate summary reports of multiple projects.

With faces you can build your own knowledge-base for reusing experiences of former projects and improve your planning.

Faces supports several methods for estimating projects, e.g. faces has special support for the delphi estimation method.

In faces you are able to register the performed efforts and compare them to the planned efforts. The real and planed costs can be tracked to create a cost profit analysis of your projects.


Faces is Open Source software licensed under the GNU GPL.

View the documentation online

Examples and screenshots, we all want that!

Wednesday, September 07, 2005


py2exe 0.6.1 released (2005/09/05)

Can now create single file executables.

What's new in py2exe 0.6

  • The new --bundle <level> or -b <level> command line switch instructs py2exe to bundle needed dlls and pyds into the library file or the executable itself, instead of simply collecting them in the dist directory. Not only does this create less files you have to distribute, it also allows Python inprocess COM servers to run completely isolated from other Python interpreters in the same process. See below for more details.

  • To prevent unicode encoding error, py2exe now by default includes the codecs module and the encodings package. If you are sure your program never implicitely or explicitely has to convert between unicode and ascii strings this can be prevented by the --ascii or -a command line switch.

  • It is no longer required to clean the build directory from time to time to prevent some strange errors.

  • Several patches have been integrated (if you miss a patch you sent me, please send it again. It can be that I missed some mails).

Tuesday, September 06, 2005

oneliner: Flatten a dict with lists

How nice and simple this is:

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> d = {'a':[1], 'b':[2,3], 'c':[4,5,6]}
>>> sum(d.values(), [])
[1, 4, 5, 6, 2, 3]

That's because sum can use a start value :)
>>> help(sum)
Help on built-in function sum:

sum(sequence, start=0) -> value

Returns the sum of a sequence of numbers (NOT strings) plus the value
of parameter 'start'. When the sequence is empty, returns start.

Monday, September 05, 2005

Quick references

You might want to investigate these links, found through Cheat Sheet Roundup

Regards to all of you who've written these sheets.. They're great!

Ceryle - a complex freemind?

Ceryle is a free tool to help you get organized. If you use a lot of post it notes, are a writer, journalist, researcher, student, or anyone compiling a lot of information for a project, maybe just trying to organize your recipes, bookmarks, or your MP3 collection, Ceryle is designed to assist you in keeping track of things. Ceryle includes features to help you store, find and even visualize your information, using what is called a graph visualization. Those same graphs also enable you to create structures for your documents, see relationships between ideas, and even generate composite documents based on those structures, like building a book from its chapters or a screenplay from its scenes.
The Ceryle Project hompage

Wikiwyg - Wiki fckeditor

Welcome to the Wikiwyg home page. Wikiwyg is the simple way to add Wysiwyg editing to your existing social software project.

Thursday, September 01, 2005

Python + Vim

ttp:// has a blog about VIM with Python built in. You can script VIM with Python. is a script that allows you to use PyDoc from within VIM, so you can look up documentation on modules while coding. pydiction is a special dictionary file of Python modules for use with vim's completion feature. is a plug in for running Python scripts from within VIM. allows you to run PyChecker from within VIM.

The above list is shamelessly ripped from this post by projecktzero