On Thursday, September 23, 2010 07:57:39 am Jacek Kałucki wrote:
> Użytkownik Ed Leafe napisał:
> >     It returns an integer, not a tuple. The duplication is because you are
> >     using enumerate(); the iterator returns the row number itself.
> 
> Your approach completely disagrees with Python iterators idea.
> In Python documentation about 'next()' method you can read:
>      'Return the next item from the container.'
> Accordingly to that definition, your bizobj is just integer object list,
> where
>      enumerate(biz.bizItererator) = enumerate(range(biz.RowCount))
> with one exception, pointer movements.
> In your opinion, enumeration of list ["a", "b", "c"], should return [0,
> 1, 2],
> and you are telling me, that functions like enumerate(), map(), etc.
> are needless with iterators.
> Sorry, but there is no sense in existence of such iterable object.
> And I completely disagree with you in that matter.
> 
> >> Since bizobj is, in simplification, collection of rows,
> >> don't you think that I should rather receive tuple of row number and row
> >> itself,
> >> like (0, row0_object)?
> >> 
> >     Well, it could, but it would have to be separate from the bizobj 
> > dataset. 
In other words, "biz.Record" is not a fixed set of data, but returns whatever 
record the bizobj is pointed at at the moment. If it were to return biz.Record 
instead of biz.RowNumber, you could not persist that reference. Maybe an 
example would make that clearer: let's assume we have a bizobj with 10 rows, 
and a column named 'century'. Each row's 'century' column is 100 x the row 
number: e.g., row 1 == 100, row 3 == 300, etc. Now consider this code, which 
assumes that the iterator returns the biz.Record instead:
> > thirdrow = None
> > 
> > for rownum, record in biz.bizIterator():
> >     if rownum == 3:
> >             thirdrow = record
> > 
> > print thirdrow.century
> > 
> >     Since we only captured the record on the third row, we would expect 
'thirdrow.century' to be equal to 300, right? But it would be equal to 1000, 
the value on the last record, since that's where the pointer is. Now consider 
we did:
> > biz.first()
> > print thirdrow.century
> > 
> >     Again, it would print 100, not 300.
> >     
> >     The other option is to return the dataset tuple for that row. That would
> >     fix the problem above, but would not allow you to modify that data and
> >     have it update the bizobj. IOW, if you changed a value in the returned
> >     data, it would not affect the data in the bizobj.
> 
> Yes!!! This is exactly what I expect from iterator.
> And this is true for each iterator for mutable objects, not for Record
> only. And I'm completely not interested what is the 'record' value outside
> the loop.
> 
> >     The whole purpose of the bizIterator is to avoid having to write code 
like this:
> > biz.first()
> > 
> > while True:
> >     try:
> >             biz.dosomething()
> >             biz.next()
> >     
> >     except dabo.dException.EndOfFileException:
> >             break
> 
> In other words, current iterator is equivalent to:
> 
> for i=0 to biz.RowCount:
>      biz.moveToRowNumber(i)
>      dosomething()
> 
> You tell me I must use something like:
> 
> for rownum, rownum_too in biz.bizIterator():
>       doSomething(biz.Record)
> 
> while I can just use:
> 
>       map(doSomething, biz.bizIterator())
> 
> 
> I know, I don't convince you Ed, so I even don't intend to do.
> Thanks for time, Ed.
> EOT

I see your EOT.  However, I'd like to offer my .02.  It's true that the use of 
iterator differs from python.  But coming from a database perspective it also 
applies.  And I believe that's exactly what Ed was thinking when he named the 
bizIterator.   Coming from the database world I new exactly what it did just 
by reading the name.  I don't believe anywhere it is suggested that the 
bizIterator is a python iterator.  I think you assumed that it was.  Where I 
assumed it was a way to read each row from a dataset.

Johnf
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to