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


Groups > comp.lang.python > #95952

Re: continue vs. pass in this IO reading and writing

Path csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.roellig-ltd.de!open-news-network.org!border2.nntp.ams1.giganews.com!nntp.giganews.com!usenetcore.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'context': 0.05; 'except:': 0.07; 'filename': 0.07; 'behave': 0.09; 'collections': 0.09; 'csv': 0.09; 'executes': 0.09; 'get.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'utilizing': 0.09; 'python': 0.10; 'jan': 0.11; 'exception': 0.13; 'interpreter': 0.15; "'break'": 0.16; 'conditional': 0.16; 'ordereddict': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:continue': 0.16; 'subject:pass': 0.16; 'subject:writing': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'shell': 0.18; 'pass': 0.22; 'am,': 0.23; 'this:': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'header': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'handling': 0.27; 'print': 0.30; 'run': 0.33; 'jump': 0.33; 'raised': 0.33; '(for': 0.34; 'editor': 0.34; 'except': 0.34; 'false': 0.35; '(and': 0.36; 'beginning': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'skip:z 10': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'questions': 0.40; 'back': 0.62; 'here': 0.66; 'subject:. ': 0.67; 'uncertain': 0.84; 'subject:this': 0.85; 'received:fios.verizon.net': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: continue vs. pass in this IO reading and writing
Date Thu, 3 Sep 2015 12:05:28 -0400
References <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-98-114-97-173.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0
In-Reply-To <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.79.1441296357.8327.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1441296357 news.xs4all.nl 23742 [2001:888:2000:d::a6]:52995
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95952

Show key headers only | View raw


On 9/3/2015 11:05 AM, kbtyo wrote:

> I am experimenting with many exception handling and utilizing continue vs pass.

'pass' is a do-nothing place holder.  'continue' and 'break' are jump 
statements

[snip]

> However, I am uncertain as to how this executes in a context like this:
>
> import glob
> import csv
> from collections import OrderedDict
>
> interesting_files = glob.glob("*.csv")
>
> header_saved = False
> with open('merged_output_mod.csv','w') as fout:
>
>      for filename in interesting_files:
>          print("execution here again")
>          with open(filename) as fin:
>              try:
>                  header = next(fin)
>                  print("Entering Try and Except")
>              except:
>                  StopIteration
>                  continue
>              else:
>                  if not header_saved:
>                      fout.write(header)
>                      header_saved = True
>                      print("We got here")
>                  for line in fin:
>                      fout.write(line)
>
> My questions are (for some reason my interpreter does not print out any readout):
>
> 1. after the exception is raised does the continue return back up to the beginning of the for loop (and the "else" conditional is not even encountered)?
>
> 2. How would a pass behave in this situation?

Try it for yourself.  Copy the following into a python shell or editor 
(and run) see what you get.

for i in [-1, 0, 1]:
     try:
         j = 2//i
     except ZeroDivisionError:
         print('infinity')
         continue
     else:
         print(j)

Change 'continue' to 'pass' and run again.

-- 
Terry Jan Reedy

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


Thread

continue vs. pass in this IO reading and writing kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-09-03 08:05 -0700
  Re: continue vs. pass in this IO reading and writing Chris Angelico <rosuav@gmail.com> - 2015-09-04 01:27 +1000
    Re: continue vs. pass in this IO reading and writing kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-09-03 08:38 -0700
      Re: continue vs. pass in this IO reading and writing Chris Angelico <rosuav@gmail.com> - 2015-09-04 01:51 +1000
        Re: continue vs. pass in this IO reading and writing kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-09-03 08:57 -0700
          Re: continue vs. pass in this IO reading and writing Chris Angelico <rosuav@gmail.com> - 2015-09-04 02:11 +1000
            Re: continue vs. pass in this IO reading and writing kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-09-03 09:35 -0700
    Re: continue vs. pass in this IO reading and writing kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-09-03 08:49 -0700
  Re: continue vs. pass in this IO reading and writing Terry Reedy <tjreedy@udel.edu> - 2015-09-03 12:05 -0400
  Re: continue vs. pass in this IO reading and writing Luca Menegotto <otlucaDELETE@DELETEyahoo.it> - 2015-09-03 18:37 +0200

csiph-web