Rameen Rastan
Rameen Rastan

Reputation: 143

How to access a previous row in pymssql in python?

For example, if I iterate over a query using:

for row in cursor:

And I want to make a comparison like:

if row[0] == previousrow[0]:
     #do something

How can I actually access the previous row?

Upvotes: 0

Views: 52

Answers (1)

Patrick Bell
Patrick Bell

Reputation: 769

If you wanted to access the previous row from your for loop, you could use the following code.

previousrow = None

for row in cursor:
    if (!(previousrow is None)):
        # do your comparison with previous row and row here
    previousrow = row

I don't write Python, but I think this compiles and should work for you.

Upvotes: 1

Related Questions