Help with generators outside of loops.

Robert Brewer fumanchu at amor.org
Wed Dec 8 00:53:40 CET 2004


Christopher J. Bottaro wrote:
> I have a generator that works like this:
> 
> for row in obj.ExecSQLQuery(sql, args):
>         # process the row
> 
> Now there are some querys that run where I know the result 
> will only be a
> single row.  Is there anyway to get that single row from the generator
> without having to use it in a for loop?  I want to do 
> something like this:
> 
> row = obj.ExecSQLQuery(sql, args)[0]
> 
> But I'm guessing that you can't index into a generator as if 
> it is a list.

row = obj.ExecSQLQuery(sql, args).next()


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list