Re: else in try/except

2011-11-15 Thread Robert Kern
On 11/15/11 2:31 PM, Grant Edwards wrote: On 2011-11-15, Barry W Brown wrote: I thought that the point of the else clause is that it is reached only if there is no exception in the try clause. Not really. If that's all you wanted, then you just put the code at the end of the try block. No

Re: else in try/except

2011-11-15 Thread Grant Edwards
On 2011-11-15, Barry W Brown wrote: > I thought that the point of the else clause is that it is reached > only if there is no exception in the try clause. Not really. If that's all you wanted, then you just put the code at the end of the try block. -- Grant Edwards grant.b.edwar

Re: else in try/except

2011-11-14 Thread Barry W Brown
I thought that the point of the else clause is that it is reached only if there is no exception in the try clause. -- http://mail.python.org/mailman/listinfo/python-list

Re: else in try/except

2011-11-14 Thread Ethan Furman
Thanks, all! ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: else in try/except

2011-11-14 Thread Chris Kaynor
On Mon, Nov 14, 2011 at 2:59 PM, MRAB wrote: > On 14/11/2011 21:53, Ethan Furman wrote: >> >> The code in 'else' in a 'try/except/else[/finally]' block seems >> pointless to me, as I am not seeing any difference between having the >> code in the 'else' suite vs having the code in the 'try' suite.

Re: else in try/except

2011-11-14 Thread Arnaud Delobelle
On 14 November 2011 21:53, Ethan Furman wrote: > The code in 'else' in a 'try/except/else[/finally]' block seems pointless to > me, as I am not seeing any difference between having the code in the 'else' > suite vs having the code in the 'try' suite. > > Can anybody shed some light on this for me?

Re: else in try/except

2011-11-14 Thread MRAB
On 14/11/2011 21:53, Ethan Furman wrote: The code in 'else' in a 'try/except/else[/finally]' block seems pointless to me, as I am not seeing any difference between having the code in the 'else' suite vs having the code in the 'try' suite. Can anybody shed some light on this for me? The differe

else in try/except

2011-11-14 Thread Ethan Furman
The code in 'else' in a 'try/except/else[/finally]' block seems pointless to me, as I am not seeing any difference between having the code in the 'else' suite vs having the code in the 'try' suite. Can anybody shed some light on this for me? ~Ethan~ -- http://mail.python.org/mailman/listinfo/p

Re: What's the use of the else in try/except/else?

2009-05-22 Thread Lawrence D'Oliveiro
In message <8dc983db-b8c4-4897- a58b-969ca5f8e...@g20g2000vba.googlegroups.com>, Beni Cherniavsky wrote: > And yes, it's icky - not because of the ``else`` but because > aquisition-release done correctly is always an icky pattern. Only in the presence of exceptions. -- http://mail.python.org/ma

Re: What's the use of the else in try/except/else?

2009-05-17 Thread Beni Cherniavsky
[Long mail. You may skip to the last paragraph to get the summary.] On May 12, 12:35 pm, Steven D'Aprano wrote: > To really be safe, that should become: > > try: >     rsrc = get(resource) > except ResourceError: >     log('no more resources available') >     raise > else: >     try: >         do

Re: What's the use of the else in try/except/else?

2009-05-14 Thread Andre Engels
On Thu, May 14, 2009 at 6:39 AM, ma wrote: > A really great use for try/except/else would be if an object is > implementing its own __getitem__ method, so you would have something > like this: > > class SomeObj(object): >    def __getitem__(self, key): >                try: >                      

Re: What's the use of the else in try/except/else?

2009-05-13 Thread ma
That's great to know! Thanks for that explanation, I am refactoring something and I was going to make ample use of assertion as I thought it was the same as C's assertion without the NDEBUG flag. On Thu, May 14, 2009 at 1:03 AM, Steven D'Aprano wrote: > On Thu, 14 May 2009 00:39:35 -0400, ma wro

Re: What's the use of the else in try/except/else?

2009-05-13 Thread Steven D'Aprano
On Thu, 14 May 2009 00:39:35 -0400, ma wrote: > A really great use for try/except/else would be if an object is > implementing its own __getitem__ method, so you would have something > like this: > > class SomeObj(object): > def __getitem__(self, key): > try: >

Re: What's the use of the else in try/except/else?

2009-05-13 Thread ma
A really great use for try/except/else would be if an object is implementing its own __getitem__ method, so you would have something like this: class SomeObj(object): def __getitem__(self, key): try: #sometype of assertion here based on key type

Re: What's the use of the else in try/except/else?

2009-05-13 Thread Steven D'Aprano
On Wed, 13 May 2009 20:44:27 +1200, Lawrence D'Oliveiro wrote: > In message , > Steven D'Aprano wrote: > >> On Tue, 12 May 2009 09:20:36 +, Steven D'Aprano wrote: >> >>> It seems pretty straightforward to me. >> >> Except of course such a pattern won't work ... > > I rest my case. Gosh, wi

Re: What's the use of the else in try/except/else?

2009-05-13 Thread Scott David Daniels
greg wrote: kj wrote: Wow. As rationales for syntax constructs go, this has got to be the most subtle one I've ever seen... It's to avoid masking bugs. Suppose you accidentally wrote try: v = mumble.field sys.warming('field was actually there?') except AttributeError: pass

Re: What's the use of the else in try/except/else?

2009-05-13 Thread Lawrence D'Oliveiro
In message , Steven D'Aprano wrote: > On Tue, 12 May 2009 09:20:36 +, Steven D'Aprano wrote: > >> It seems pretty straightforward to me. > > Except of course such a pattern won't work ... I rest my case. -- http://mail.python.org/mailman/listinfo/python-list

Re: What's the use of the else in try/except/else?

2009-05-12 Thread greg
kj wrote: Wow. As rationales for syntax constructs go, this has got to be the most subtle one I've ever seen... It's to avoid masking bugs. Suppose you accidentally wrote try: v = mumble.field sys.warming('field was actually there?') except AttributeError: pass Then you coul

Re: What's the use of the else in try/except/else?

2009-05-12 Thread Carl Banks
On May 12, 2:35 am, Steven D'Aprano wrote: > On Tue, 12 May 2009 09:20:36 +, Steven D'Aprano wrote: > > On Tue, 12 May 2009 20:23:25 +1200, Lawrence D'Oliveiro wrote: > > >> In message , kj wrote: > > >>> I know about the construct: > > >>> try: > >>>     # do something > >>> except ...: > >>>

Re: What's the use of the else in try/except/else?

2009-05-12 Thread Peter Pearson
On 12 May 2009 09:35:36 GMT, Steven D'Aprano wrote: [snip] > To really be safe, that should become: > > try: > rsrc = get(resource) > except ResourceError: > log('no more resources available') > raise > else: > try: > do_something_with(rsrc) > finally: > rsrc.clo

Re: What's the use of the else in try/except/else?

2009-05-12 Thread Steven D'Aprano
On Tue, 12 May 2009 09:20:36 +, Steven D'Aprano wrote: > On Tue, 12 May 2009 20:23:25 +1200, Lawrence D'Oliveiro wrote: > >> In message , kj wrote: >> >>> I know about the construct: >>> >>> try: >>> # do something >>> except ...: >>> # handle exception >>> else: >>> # do someth

Re: What's the use of the else in try/except/else?

2009-05-12 Thread Steven D'Aprano
On Tue, 12 May 2009 20:23:25 +1200, Lawrence D'Oliveiro wrote: > In message , kj wrote: > >> I know about the construct: >> >> try: >> # do something >> except ...: >> # handle exception >> else: >> # do something else >> >> ...but I can't come with an example in which the same coul

Re: What's the use of the else in try/except/else?

2009-05-12 Thread Lawrence D'Oliveiro
In message , kj wrote: > I know about the construct: > > try: > # do something > except ...: > # handle exception > else: > # do something else > > ...but I can't come with an example in which the same couldn't be > accomplished with [no else] I'd agree. If you have to resort to a "

Re: What's the use of the else in try/except/else?

2009-05-11 Thread kj
In Scott David Daniels writes: >kj wrote: >> ... I can't come with an example in which the same couldn't be >> accomplished with >> >> try: >> # do something >> # do something else >> except ...: >> # handle exception >> >> The only significant difference I can come up with is th

Re: What's the use of the else in try/except/else?

2009-05-10 Thread Scott David Daniels
kj wrote: ... I can't come with an example in which the same couldn't be accomplished with try: # do something # do something else except ...: # handle exception The only significant difference I can come up with is that in the second form, the except clause may be masking some une

What's the use of the else in try/except/else?

2009-05-10 Thread kj
I know about the construct: try: # do something except ...: # handle exception else: # do something else ...but I can't come with an example in which the same couldn't be accomplished with try: # do something # do something else except ...: # handle exception The only