Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-13 Thread Arnaud Delobelle
Nobody writes: > On Mon, 11 Oct 2010 05:42:39 -0700, Ethan Furman wrote: > If I'm catching exceptions in order to perform clean-up, I'll use a bare except and re-raise the exception afterwards. In that situation, a bare except is usually the right thing to do. >>> >>> Wrong way to do

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-11 Thread Nobody
On Mon, 11 Oct 2010 05:42:39 -0700, Ethan Furman wrote: >>>If I'm catching exceptions in order to perform clean-up, I'll use a bare >>>except and re-raise the exception afterwards. In that situation, a bare >>>except is usually the right thing to do. >> >> Wrong way to do it. > > What, then, is

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-11 Thread Ethan Furman
Lawrence D'Oliveiro wrote: In message , Nobody wrote: If I'm catching exceptions in order to perform clean-up, I'll use a bare except and re-raise the exception afterwards. In that situation, a bare except is usually the right thing to do. Wrong way to do it. What, then, is the right way to

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-11 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, 05 Oct 2010 13:57:11 +1100, Ben Finney wrote: > >> chad writes: >> >>> while 1: >> >> A minor point: this is more explanatory and less misleading if you write >> it as ‘while True’. > > Why is it misleading? Is there some circumstance in Python where the > lit

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-11 Thread Lawrence D'Oliveiro
In message , Nobody wrote: > If I'm catching exceptions in order to perform clean-up, I'll use a bare > except and re-raise the exception afterwards. In that situation, a bare > except is usually the right thing to do. Wrong way to do it. -- http://mail.python.org/mailman/listinfo/python-list

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-05 Thread Nobody
On Tue, 05 Oct 2010 13:57:11 +1100, Ben Finney wrote: > Here's your problem. Don't ever use a bare ‘except’ unless you know > exactly why you're doing so. Rather, figure out what exception types you > want to catch, and catch *only* those types. If I use a bare except, I usually have a good reaso

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-05 Thread Steven D'Aprano
On Tue, 05 Oct 2010 11:13:53 +0800, Von wrote: > Try to use sys.exit(0) > Maybe you should print out the error in your except block. Not exiting with a status-code of 0 is no more helpful than not exiting with a status-code of 1. It's actually *less* helpful, if the intention is actually to exi

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-05 Thread Lawrence D'Oliveiro
In message , Seebs wrote: > On 2010-10-05, Lawrence D'Oliveiro > wrote: > >> In message <87iq1hz6rc@benfinney.id.au>, Ben Finney wrote: >> >>> Don't ever use a bare ‘except’ unless you know exactly why you're doing >>> so. >> >> In other news, don’t ever put a loaded gun in your mouth and pul

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Seebs
On 2010-10-05, Lawrence D'Oliveiro wrote: > In message <87iq1hz6rc@benfinney.id.au>, Ben Finney wrote: >> Don't ever use a bare ???except??? unless you know exactly why you're doing >> so. > In other news, don???t ever put a loaded gun in your mouth and pull the > trigger unless you know exa

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Lawrence D'Oliveiro
In message <87iq1hz6rc@benfinney.id.au>, Ben Finney wrote: > Don't ever use a bare ‘except’ unless you know exactly why you're doing > so. In other news, don’t ever put a loaded gun in your mouth and pull the trigger unless you know exactly why you’re doing so. Some people have a problem. T

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Ben Finney
Steven D'Aprano writes: > Why is it misleading? Is there some circumstance in Python where the > literal 1 could have a false value? It's misleading as to the intent. > "while 1" was the accepted idiom for infinite loops in Python for many > years, before the introduction of bools in (I think

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Steven D'Aprano
On Tue, 05 Oct 2010 13:57:11 +1100, Ben Finney wrote: > chad writes: > >> while 1: > > A minor point: this is more explanatory and less misleading if you write > it as ‘while True’. Why is it misleading? Is there some circumstance in Python where the literal 1 could have a false value? "whil

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Von
Try to use sys.exit(0) Maybe you should print out the error in your except block. 2010/10/5, chad : > Given the following.. > > #!/usr/bin/python > > import urllib2 > import sys > import time > > while 1: > try: > con = urllib2.urlopen("http://www.google.com";) > data = con.re

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Terry Reedy
On 10/4/2010 10:38 PM, chad wrote: Given the following.. #!/usr/bin/python import urllib2 import sys import time while 1: try: con = urllib2.urlopen("http://www.google.com";) data = con.read() print "connected" #The loop doesn't exit if I use sys.exit(1

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Ben Finney
chad writes: > while 1: A minor point: this is more explanatory and less misleading if you write it as ‘while True’. > try: > con = urllib2.urlopen("http://www.google.com";) > data = con.read() > print "connected" > #The loop doesn't exit if I use sys.exit(1)

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Justin Ezequiel
your bare except is catching the SystemExit raised by sys.exit(1) -- http://mail.python.org/mailman/listinfo/python-list

I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread chad
Given the following.. #!/usr/bin/python import urllib2 import sys import time while 1: try: con = urllib2.urlopen("http://www.google.com";) data = con.read() print "connected" #The loop doesn't exit if I use sys.exit(1) break except: time.s