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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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.