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
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
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
Thanks, all!
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
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.
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?
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
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
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
[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
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:
>
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
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:
>
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
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
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
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
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
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 ...:
> >>>
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
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
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
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 "
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
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
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
26 matches
Mail list logo