Re: Nested loop
- From: Juho Schultz <juho.schultz@xxxxxxxxxxx>
- Date: Wed, 30 Nov 2005 10:22:33 +0200
viewcharts wrote:
I am reading two text files comparing the values in one to the other, this requires two loops. The problem is that when the inner loop is finished, it never goes back into the loop. Any suggestions?
for refSymbol in symbols.readlines():
for lookupSymbol in myfile.readlines(): showme = lookupSymbol.split('\t')
if showme[3] == refSymbol.strip():
priceNew.write(refSymbol.strip()+" "+showme[10])
When the inner loop is finished for the 1st time, myfile has been read. So next time you start to the loop, myfile.readlines() returns an empty list.
Something like this should be better:
lookupSymList = myfile.readlines()
for refSymbol in symbols.readlines():
for lookupSymbol in lookupSymList:
showme = lookupSymbol.split('\t')
if showme[3] == refSymbol.strip():
priceNew.write(refSymbol.strip()+" "+showme[10])
.- References:
- Nested loop
- From: viewcharts
- Nested loop
- Prev by Date: [Announce] boost.date_time library Python bindings
- Next by Date: Re: Nested loop
- Previous by thread: Nested loop
- Next by thread: Re: Nested loop
- Index(es):
Relevant Pages
|