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.
--
[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:
On Thu, May 14, 2009 at 6:39 AM, ma mabdelka...@gmail.com 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:
In message pan.2009.05.12.09.35...@remove.this.cybersource.com.au, 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.
--
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
On Wed, 13 May 2009 20:44:27 +1200, Lawrence D'Oliveiro wrote:
In message pan.2009.05.12.09.35...@remove.this.cybersource.com.au,
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
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 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:
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
ste...@remove.this.cybersource.com.au wrote:
On
In message gu7f97$mt...@reader1.panix.com, 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
On Tue, 12 May 2009 20:23:25 +1200, Lawrence D'Oliveiro wrote:
In message gu7f97$mt...@reader1.panix.com, 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
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 gu7f97$mt...@reader1.panix.com, kj wrote:
I know about the construct:
try:
# do something
except ...:
# handle exception
else:
# do
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.close()
On May 12, 2:35 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au 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 gu7f97$mt...@reader1.panix.com, kj wrote:
I know about the construct:
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
In w_adny5q3jzyxjrxnz2dnuvz_u2dn...@pdx.net Scott David Daniels
scott.dani...@acm.org 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
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
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
18 matches
Mail list logo