Jump to content

Resetting iterators


Recommended Posts

I have the following code

	    cur.execute("select symbol,stopPrice from holdings order by symbol" )
    for row in cur:
        newSym =str(row[0])
                syms = newSym
                syms += ","+newSym
	    holdingStops = BuildMyDict(cur)

	def BuildMyDict(response):
    myDict = dict()
    for r in response:
        myDict[r[0]] = float(r[1])
    return myDict

When I get to the BuldMyDict it believes the cur has already completed.  Is there a command that will reset the iterator counter?

Link to comment
Share on other sites

First, verify that it actually can iterate through the data set twice, by trying a for loop right after the first one. If it can't iterate twice, then you call fetchall() to obtain a list and store that in another variable instead. You will be able to iterate over a generic Python list as many times as you need to.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...