Re: Help with generators outside of loops.

2004-12-08 Thread David Eppstein
In article <[EMAIL PROTECTED]>, Andrea Griffini <[EMAIL PROTECTED]> wrote: > Isn't the handling of StopIteration confined in the very moment of > calling .next() ? This was what I expected... and from a simple test > looks also what is happening... Not if someone farther back in the call chain i

Re: Help with generators outside of loops.

2004-12-08 Thread Steven Bethard
Christopher J. Bottaro wrote: Wow, good advice. One question, how is the generator class implemented so that if assigned to a tuple/list, it knows what to do? Is it possible to overload the assignment operator kinda like in C++? Tuple unpacking works with generators because generators implement t

Re: Help with generators outside of loops.

2004-12-08 Thread Christopher J. Bottaro
Steven Bethard wrote: > I don't do much with SQL/databases stuff, but if you really know the > result will be a single row, you can take advantage of tuple unpacking > and do something like: > > row, = obj.ExecSQLQuery(sql, args) > > or > > [row] = obj.ExecSQLQuery(sql, args) > > This has the a

Re: Help with generators outside of loops.

2004-12-08 Thread Andrea Griffini
David Eppstein wrote: In article <[EMAIL PROTECTED]>, "Robert Brewer" <[EMAIL PROTECTED]> 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()

Re: Help with generators outside of loops.

2004-12-07 Thread Steven Bethard
Robert Brewer wrote: 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 genera

Re: Help with generators outside of loops.

2004-12-07 Thread David Eppstein
In article <[EMAIL PROTECTED]>, "Robert Brewer" <[EMAIL PROTECTED]> 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

RE: Help with generators outside of loops.

2004-12-07 Thread Robert Brewer
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 generato