help with lists and writing to file in correct order

Steven D'Aprano steve at REMOVETHIScyber.com.au
Mon Dec 26 21:08:42 EST 2005


On Mon, 26 Dec 2005 17:44:43 -0800, homepricemaps wrote:

> sorry guys, here is the code
> 
>     for incident in bs('a',  {'class' : 'price'}):
>         price = ""
>         for oText in incident.fetchText( oRE):
>               price += oText.strip() + "','"
> 
>     for incident in bs('div',  {'class' : 'store'}):
>         store = ""
>         for oText in incident.fetchText( oRE):
>             store += oText.strip() + "','"
> 
>     for incident in bs('h2',  {'id' : 'food'}):
>       food = ""
>       for oText in incident.fetchText( oRE):
>             food += oText.strip() + "','"


This is hardly all your code -- where is the part where you actually
*write* something to the file? The problem is you are writing the same
store and food to the file over and over again. After you have collected
one line of store/food, you must write it to the file immediately, or at
least save it in a list so you can write the lot at the end.


-- 
Steven.




More information about the Python-list mailing list