Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

2007/10/13

Python and comma

The problem - there was a tuple:
t = ("abc", "def")
Somwhere inside the program was an instruction:
something = t[0]
and then
something
returned "abc".



Some time later it turned out that "def" was not necessary
in t so was modified:
t = ("abc")
and sowhere inside the program instruction
something = t[0]
made that something returned "a".

It was Bad.

Why that happened?

Beacuse t was not a tuple anymore, it became a string. Instruction t[0] returns first item in iterable so it returned "a" for us.

What was ommited?

A coma.

After the change it was (bad):
t = ("abc")
instead (good):
t = ("abc",)

The coma creates a tuple. In our case consisting of one item, but still the tuple.

2007/08/13

The implementation

The site is created using django and few applications written in django.

Just for curious.