Categories
iola

Django Alliance

Being small and agile has many advances, but sometimes people confuse it with being fragile. Although one could argue that betting on a single-vendors proprietary solution would be a more fragile business proposition. Anyway, to make people feel safer buying web systems developed in Django and Python based on Open Source, we have had a finger in the creation of the Django Alliance. The web site complements Django People with a focus on companies rather than on single individuals.

Categories
python

Python scoping

Last friday, Lau discovered an interesting edge case of python. Something that at first appeared to be a bug, but later revealed a deeper truth about the scoping of Python. I guess coming from a C++ background spoils one in some regards. Scoping in C++ is simple and uniform, I have never in many years of programming C++ got bitten by the scope of the language, something that I also can’t say about C#.

The problem boils down to how Python treats local variable and global variables. The following example, stolen and modified from here, shows the edge case in its most simple form:

a, b = (1, 2)

print(a, b)

def test():
    print(a)
    print(b)    # (A)
    #b=1       # (B)

test()

(A) works as long as (B) is commented out. The strange thing is that changing (B) into += produces the same result. Actually it is the case that += a global variable will never work, unless you have declared it in the local scope first. This comes back to the way Python threats variables in the local scope. The following link has more examples to illustrate how scoping works and also how this is different in Python 3k. As explained on Stackoverflow, using the dis functionality sheds some light on strange cases like these. All this said, the scoping has one good thing going for it. The following is quite useful and perfectly legal in Python:

i = 0

def ex1():
if i < 0:
b = 10
else:
b = 20
print b

ex1()

Categories
Blog

Generators and decorators in Python

Was reading through some old blog posts today and found an interesting talk about Coroutines and Concurrency. The talk is pretty long but presents some nice ideas about how to split a problem up and making it more modular using yielding. It seems like python has extended this a little so that you can actually use generators to consume messages also. What I found particular interesting though in the talk, was when he briefly showed a decorator. Decorators are really powerful and seems to bring about the best of lisps macro extensability to Python without loosing the excellent syntax 🙂 I googled a bit and found the following list of patterns that you can do with decorators.

Categories
iola On the web

Yayart.net launched

I’m very please to announce that we, at iola, have launched a new site for digital artists today. For the 31 days there’s a competition where you can win lots of nice stuff including an exhibition at the center of Copenhagen. The site is coded in Python (Django) and uses varnish for caching.