Re: [Tutor] How much in a "try" block?

2013-08-23 Thread Peter Otten
Alan Gauld wrote: > On 22/08/13 21:27, Chris Down wrote: > >> You can also use the "else" clause if there is stuff you want to run if >> the try block doesn't raise the caught exception, which avoids putting it >> in "try" if you don't intend to exit from the exception. > > I admit that I've nev

Re: [Tutor] How much in a "try" block?

2013-08-23 Thread leam hall
Well, maybe I'm looking at the wrong construct. The script needs to open up one file that will be on the machine. It will open up other files given as command line arguments and open files to write to. It should fail gracefully if it cannot open the files to be read or written. The community that w

Re: [Tutor] How much in a "try" block?

2013-08-23 Thread Chris Down
On 2013-08-23 01:30, Alan Gauld wrote: > Unless you really only want g(x) executed if there is no MyError exception > but want h(x) executed regardless. I've had that situation a few times before when using the logic "try this, or fall back to this if it doesn't work". > I'm curious, how often do

Re: [Tutor] How much in a "try" block?

2013-08-22 Thread Steven D'Aprano
On 23/08/13 10:30, Alan Gauld wrote: I admit that I've never really found a use for else in a try block. I don;t see much advantage in try: f(x) except MyError: pass else: g(x) h(x) over try: f(x) except MyError: pass g(x) h(x) Unless you really only want g(x) executed if the

Re: [Tutor] How much in a "try" block?

2013-08-22 Thread Oladipupo Elegbede
Depending on what x is and also whether or not you've decided to go the 'try'route, if, else may be useful from the way you sound. My thought. On 22 Aug 2013 21:16, "leam hall" wrote: > If I have a series of tasks that depend on X happening, should I put them > all in the same "try" block or just

Re: [Tutor] How much in a "try" block?

2013-08-22 Thread Amit Saha
On Fri, Aug 23, 2013 at 10:30 AM, Alan Gauld wrote: > On 22/08/13 21:27, Chris Down wrote: > >> You can also use the "else" clause if there is stuff you want to run if >> the try >> block doesn't raise the caught exception, which avoids putting it in "try" >> if >> you don't intend to exit from th

Re: [Tutor] How much in a "try" block?

2013-08-22 Thread Alan Gauld
On 22/08/13 21:27, Chris Down wrote: You can also use the "else" clause if there is stuff you want to run if the try block doesn't raise the caught exception, which avoids putting it in "try" if you don't intend to exit from the exception. I admit that I've never really found a use for else in

Re: [Tutor] How much in a "try" block?

2013-08-22 Thread Chris Down
On 2013-08-23 06:20, Amit Saha wrote: > On Fri, Aug 23, 2013 at 6:14 AM, leam hall wrote: > > If I have a series of tasks that depend on X happening, should I put them > > all in the same "try" block or just put X in there and exit out if it fails? > > You are right about the latter. You should p

Re: [Tutor] How much in a "try" block?

2013-08-22 Thread Amit Saha
On Fri, Aug 23, 2013 at 6:14 AM, leam hall wrote: > If I have a series of tasks that depend on X happening, should I put them > all in the same "try" block or just put X in there and exit out if it fails? You are right about the latter. You should put only the statement which you expect to raise

[Tutor] How much in a "try" block?

2013-08-22 Thread leam hall
If I have a series of tasks that depend on X happening, should I put them all in the same "try" block or just put X in there and exit out if it fails? Thanks! Leam -- Mind on a Mission ___ Tutor maillist - Tutor@pyth