[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnumed-devel] Re: tuples returned by run_ro_query

From: Horst Herb
Subject: Re: [Gnumed-devel] Re: tuples returned by run_ro_query
Date: Tue, 23 Sep 2003 22:18:31 +1000
User-agent: KMail/1.5.9

On Tue, 23 Sep 2003 21:47, H.Berger wrote:
> "res," is a one-element tuple. The same as "res = tuple[0]". This tuple has
> a fixed size, so it wont throw away the following parts.
> IMHO in a case like this where we expect to get sometimes two elements, we
> should actually take them:
> res, idx = run_ro_query()

The syntax
res, = ...
is typically used when a function returns a tuple/list of lists, and you know 
that the outer tuple/list contains only one inner element.

Queries typically return such tuples containing lists or dictionary objects, 
and if your query searches by primary key, you can reasonably assume that it 
will return only one or none object within the outer tuple.

Hence, *don't* use that syntax if you are not sure what the result will be.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]