Today at work I needed a http server with python to test a script that outputs something to the web. I couldn't find one near by. hadn't the time nor the will to setup one, I just postponed the task to another moment. Few seconds later WSGI came to my mind. Yes, why searching for python server when there is a http server in the paste package ? All I need is two lines of code:

from paste import httpserver
httpserver.serve(my_wsgi_app, host='127.0.0.1', port='8080')

voila !

» Read More

Since I started developing with python I never found myself in the need of such statement. As I remember I never asked where is the switch statement in this language. I think I never asked that because of the dictionary data type in python that you can use to do the same thing as a switch statement will do. I was surprised that there are many PEPs about adding the switch statement to python.

In other languages the switch statement looks like this:

switch (var)
{
case value1: do_some_stuff1();
case value2: do_some_stuff2();
...
case valueN: do_some_stuffN();
default: do_default_stuff();
}

in python one can do the same thing with the help of a dictionary like this:

» Read More

I found this problem at The Voidspace Techie Blog:
Here is it:

>>> 3.__str__()
File "", line 1
3.__str__()
^
SyntaxError: invalid syntax

Here, python thinks that the dot is the dot of a float and not a dot for an attribute.
But the following works:

» Read More

From the Project site:
PyReverse is a set of tools for reverse engineering Python code.
So far, it features dependency analysis tools, unittest skeleton generation, quick UML like diagrams generation and XMI generation for importation in a UML modeling tool. A special module can be used to generate files readable by Argo UML.

» Read More

The default python behaviour when calling a class method that does not exist is that you get an exception:

>>> class A(object):
... pass
...
>>> a = A()
>>> a.getBlablabla()
Traceback (most recent call last):
File "", line 1, in ?
AttributeError: 'A' object has no attribute 'getBlablabla'

» Read More