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


Groups > comp.lang.python > #33153

Re: writing a csv file

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'skip:o 50': 0.07; 'subject:file': 0.07; '#print': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'csv': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:writing': 0.16; 'writer': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.28; 'file': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'print': 0.32; 'function.': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'changed': 0.34; 'thanks': 0.34; 'list': 0.35; 'table': 0.35; 'received:org': 0.36; 'but': 0.36; 'data.': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; "you'll": 0.62
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: writing a csv file
Date Mon, 12 Nov 2012 00:27:52 +0000
References <4467d3df-7d0c-4566-8fed-ba7fb8b54afe@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-22-33.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:16.0) Gecko/20121026 Thunderbird/16.0.2
In-Reply-To <4467d3df-7d0c-4566-8fed-ba7fb8b54afe@googlegroups.com>
X-Antivirus avast! (VPS 121111-1, 11/11/2012), Outbound message
X-Antivirus-Status Clean
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3567.1352679962.27098.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352679962 news.xs4all.nl 6947 [2001:888:2000:d::a6]:57068
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33153

Show key headers only | 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