Path: csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'append': 0.07; 'lines.': 0.07; 'cc:addr:python-list': 0.09; '"in': 0.09; 'csv': 0.09; 'executes': 0.09; 'skipping': 0.09; 'exception': 0.13; '(but': 0.15; 'file,': 0.15; 'headers': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'headers.': 0.16; 'merge,': 0.16; 'subject:continue': 0.16; 'subject:pass': 0.16; 'subject:writing': 0.16; 'wrote:': 0.16; 'module,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'algorithm': 0.20; 'meant': 0.22; 'saying': 0.22; 'body,': 0.22; 'sep': 0.22; 'am,': 0.23; 'seems': 0.23; 'specified': 0.23; 'header:In-Reply- To:1': 0.24; '(which': 0.26; 'fri,': 0.27; 'respective': 0.27; 'message-id:@mail.gmail.com': 0.27; 'values': 0.28; '"do': 0.29; 'block,': 0.29; 'header,': 0.29; 'raise': 0.29; 'probably': 0.31; 'case,': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.37; 'doing': 0.38; 'thank': 0.38; 'files': 0.38; 'means': 0.39; "didn't": 0.39; 'save': 0.60; 'your': 0.60; 'entire': 0.61; 'further': 0.62; 'hear': 0.64; 'subject:. ': 0.67; "'try'": 0.84; 'chrisa': 0.84; 'cut-off': 0.84; "that'll": 0.84; 'subject:this': 0.85; 'to:none': 0.91; 'hassle': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=hD+ekBucajZoVR7oAP/0vKF8jEGQVbiDe6CB07suED0=; b=g/vqKkwxwHVNtGsEAUyDhlsxntkVB27FFY4FkEkT+LoMQF2bJg0KmDp+wO1/XeoIMb lTZ/e6fZKJ6pmdBslItpB/AMhsGS6ZMHpf0+wCqRn1XYonpM+09M5lxPY62QJJfE8Eue 0RuvSHxEk/09VSiAWuCThUCNXGyu0FTx58iNfeEZ2JJ2RuH/BvVPS/iaIzsb7M41adjB Yq5zOcImwdh07ZG7o9ttKrQDl8EN0h+Gy0TSK4W45lxok7Q3xLho3kNTmLRHHtBIjewA NkKLRro3A22SVEtSGgpi9OjrvL2CN83BzVa42DaNS5iPZh8d/942bK8jd7RFdNdaSu7b fTdA== MIME-Version: 1.0 X-Received: by 10.50.98.7 with SMTP id ee7mr14486957igb.13.1441295517305; Thu, 03 Sep 2015 08:51:57 -0700 (PDT) In-Reply-To: <53c5301c-2833-446f-a7d1-6c0ef9314928@googlegroups.com> References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> <53c5301c-2833-446f-a7d1-6c0ef9314928@googlegroups.com> Date: Fri, 4 Sep 2015 01:51:57 +1000 Subject: Re: continue vs. pass in this IO reading and writing From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441295521 news.xs4all.nl 23867 [2001:888:2000:d::a6]:32812 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95948 On Fri, Sep 4, 2015 at 1:38 AM, kbtyo wrote: > Thank you for the elaboration. So, what I hear you saying is that (citing, "In this case, there's no further body, so it's going to be the same as "pass" (which > means "do nothing")") that the else block is not entered. For exma Seems like a cut-off paragraph here, but yes. In a try/except/else block, the 'else' block executes only if the 'try' didn't raise an exception of the specified type(s). > Do you mind elaborating on what you meant by "compatible headers?". The files that I am processing may or may not have the same headers (but if they do they should add the respective values only). > Your algorithm is basically: Take the entire first file, including its header, and then append all other files after skipping their first lines. If you want a smarter form of CSV merge, I would recommend using the 'csv' module, and probably doing a quick check of all files before you begin, so as to collect up the full set of headers. That'll also save you the hassle of playing around with StopIteration as you read in the headers. ChrisA