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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...