Help with generators outside of loops.
David Eppstein
eppstein at ics.uci.edu
Tue Dec 7 19:34:37 EST 2004
More information about the Python-list mailing list
Tue Dec 7 19:34:37 EST 2004
- Previous message (by thread): Help with generators outside of loops.
- Next message (by thread): Help with generators outside of loops.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <mailman.7340.1102463745.5135.python-list at python.org>, "Robert Brewer" <fumanchu at amor.org> wrote: > > But I'm guessing that you can't index into a generator as if > > it is a list. > > row = obj.ExecSQLQuery(sql, args).next() I've made it a policy in my own code to always surround explicit calls to next() with try ... except StopIteration ... guards. Otherwise if you don't guard the call and you get an unexpected exception from the next(), within a call chain that includes a for-loop over another generator, then that other for-loop will terminate without any error messages and the cause of its termination can be very difficult to track down. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/
- Previous message (by thread): Help with generators outside of loops.
- Next message (by thread): Help with generators outside of loops.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list