Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33153

Re: writing a csv file

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: writing a csv file
Date 2012-11-12 00:27 +0000
References <4467d3df-7d0c-4566-8fed-ba7fb8b54afe@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3567.1352679962.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 12/11/2012 00:05, ejsaiet@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

writing a csv file ejsaiet@alaska.edu - 2012-11-11 16:05 -0800
  Re: writing a csv file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-12 00:27 +0000

csiph-web