I'm somewhat new to Python and SQLObject (but have worked with ORM Wrappers before with Java). I have inherited a project which uses the above extensively. I have a somewhat novice question but couldn't find obvious answers so am posting here.

So the code I have basically does a .select() on a merge table and creates an output file (Comma separated say) with columns I'm interested in . I want to now additionally mark in this file -

a. duplicates that occur in succession only
b. objects that have certain values for a column

So for eg, if row X and row Y are duplicates, I want to have in the file a single row with the letter D at the end to mark Duplicate.

Whats the best way of doing this?

I thought of this pseudo-code:

for x in merge_table.select()
    retrieve next row y    ->> (how??)
    if x==y       //duplicate
       add x to file & mark appropriately in file
       add x and y to file
       reposition cursor correctly to next unread row (if needed, how?)

I was trying to find  a way to do this with SQLObject but couldn't easily figure out. I would like to avoid complicated cursor logic if I can help it.

Any pointers would be appreciated.