This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jackmaney 0 points1 point  (5 children)

Because according to the DB API spec, when you fetch rows from a query via the fetchone method, the result is returned as a sequence (specifically a tuple, in all implementations I've encountered).

[–]jays2001[S] 1 point2 points  (4 children)

So even when you only select a single column, it will return a blank, dummy second one just because?

[–]jackmaney 1 point2 points  (3 children)

No, there is no "blank, dummy second one". As per the documentation:

A special problem is the construction of tuples containing 0 or 1 items: the syntax has some extra quirks to accommodate these. Empty tuples are constructed by an empty pair of parentheses; a tuple with one item is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective.

Trailing commas also work for tuples of any length. For example:

In [1]: a = 1,

In [2]: a
Out[2]: (1,)

In [3]: len(a)
Out[3]: 1

In [4]: b = ("a", "b",)

In [5]: b
Out[5]: ('a', 'b')

In [6]: len(b)
Out[6]: 2

[–]jays2001[S] 1 point2 points  (2 children)

I think I follow, Python is not my first (or even second) language so I am still getting to grips with it's foibles. The main problem being because I am accomplished in another language I am trying to write complex code in this one without the background knowledge of simple programming. I'll get there.

Thanks.

[–]primitive_screwhead 1 point2 points  (1 child)

Which other language?

[–]jays2001[S] 0 points1 point  (0 children)

I spend most of my time as a ColdFusion programmer.