writing a csv file
Mark Lawrence
breamoreboy at yahoo.co.uk
Sun Nov 11 19:27:52 EST 2012
On 12/11/2012 00:05, ejsaiet at alaska.edu wrote:
>
> with open("/home/eyalak/Documents/weather/weather.csv", "wb") as f:
> writer = csv.writer(f)
> table = soup.findAll("table")[3]
> #print table
> for tr in table.findAll("tr", valign="top"):
> a={x.string for x in tr.findAll('td')}
> print str(a)
> writer.writerows([a])
>
> It did not work unless I changed the line a={x.string for x in tr.findAll('td')} to a=list({x.string for x in tr.findAll('td')})
>
> But that disorganizes the data. How can I write the data to a csv file without altering the order prior to the list function.
> Thanks
> E
>
Change the line print str(a) to print type(a), a
You'll see what the problem is and be able to fix it.
--
Cheers.
Mark Lawrence.
More information about the Python-list
mailing list