Archive for the 'Python' Category

Curly braces, go away!

Wednesday, February 9th, 2005

It’s good to hear that I’m not the only one hating curly braces. Taste for the web.

Exploring the depths of Sourceforge, Python projects

Wednesday, January 26th, 2005

Sourceforge contains many well known and even more unknown open source projects. With this post I will highlight some less known but still very useful Python based projects.

Python bindings to the Google API allows you to do Google searches, retrieve pages from the Google cache, and ask Google for spelling suggestions.

Karrigell is a simple, lightweight but full-featured web framework, written in Python. Includes builtin server, object-relational modules for gadfly and sqlite, python in html or html in python modes, decent documentation. Looks like a friendly environment for learnign web programming with Python.

PyWebMail is a Python library and collection of tools for working with WebMail servers (POP3, SMTP etc.)

Pyana is an extension module that allows Python programs to interface with the Apache Software Foundation’s Xalan XSLT transformation engine.

Snakelets is a servlet-like web app framework, probably ideal for ex-Java programmers.

PyDBDesigner is a free relational database modeling tool that is planned to be able to design both logical and physical models similarly to Erwin(c) and PowerDesigner. Its goal is to provide a useful toolset that allows developers analysts and database designers to design and develop databases from the verbal model to the schemas and SQL scripts.

Venster is a highly native Windows GUI toolkit for Python based on the ctypes ffi library. The aim of Venster is to be a very lightweight wrapper around the standard Win32 API, making it easy to write slick windows applications in pure Python.

Scratchy is an Apache Web Server log parser and HTML report generator written in Python.

Deleteting a many-to-many relation with SQLObject

Tuesday, January 4th, 2005

If you have the need to delete an object with SQLObject you will probably like to delete a many-to-many relation some time too. First, I have to establish the relation. It’s explained in the SQLObject documentation so no details on that in this blog post. But it doesn’t say anything about how you can delete this relation. After searching the SQLObject mailing list and Wiki I finally found a clue in the source code and it’s really simple.

I am working on a website directory so I’ll just create an SQLObjectified website and an SQLObjectified category to put the website in. Categories can have many websites and websites can be placed in many categories so obviously I need a many-to-many relation. items is the module where I keep my SQLObject classes.
website = items.Website(url="http://www. .......", more="params")
category = items.Category(title="Cool category",more="params")

This establishes a website, a category and a relation between them. So if I want to move the website from that category I need to delete the relation between them. The magic code is
That’s inserting 2 objects into a database and then creating and deleting (or should I say removing?) a relation between them in 4 simple lines of code. SQLObject surely isn’t perfect and the documentation could have been more extensive but this example demonstrates that you can do things with SQLObject in a fraction of the lines you need if you’re working with SQL.

Update : The SQLObject documentation actually says that a removeCategory method is created for this, it’s just hidden away in the reference section, under RelatedJoin: Many-to-Many.

CherryPy 2 beta is out

Friday, December 31st, 2004

Details including changelog and download at the CherryPy website. My simple quickstart guide for the CherryPy 2 alpha release should still be valid.

Brilliant feature #1 : PyPe todo comments

Thursday, December 30th, 2004

The Python editor PyPe is intended to be a simple editor that includes what you need and not much more. It does however include a nice little feature that I haven’t seen anywhere else. It’s called todo comments. A comment in Python looks like this
#A comment
A # sign followed by your comment. A PyPe todo comment is a perfectly valid Python comment and looks like this
#Todo: a todo comment
That’s a # sign followed by the word todo, a colon and the todo comment. Remember that you can’t have anything in front of it, so this line
a = 5 #Todo: a todo comment
includes a valid Python comment but it is not a valid todo comment because of the python code in front of it.

So what’s special about that? Let’s first take a look at a PyPe screenshot :

PyPe screenshot showing the text area, code browser and todo box

The PyPe view consists of a text area where you write your Python code, a browsable code tree to the upper right and a box with shortcuts to your todo comments to the lower right.

Whenever you think about something that needs to be done or find a problem with your Python code that you can’t fix instantly, add a todo comment and PyPe adds it to your todo list. The todo list is built when you open your file and refreshed everytime you press F5 (note: you might have to enable todo comments in the document menu).

Example todo comments:

Screenshot of example todo comments

This results in the following todo list :

Screenshot of the corresponding PyPe todo list

You can add todo comments anywhere in your code and when you doubleclick an entry in the todo list you are taken to the line that contains the todo comment. Simple, effective and brilliant!