Help with generators outside of loops.

Christopher J. Bottaro cjbottaro at alumni.cs.utexas.edu
Wed Dec 8 00:44:14 CET 2004


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.

Thank you for the help.




More information about the Python-list mailing list