<br><br><div class="gmail_quote">On Wed, Mar 3, 2010 at 6:47 AM, Oren Elrad <span dir="ltr"><<a href="mailto:orenelrad@gmail.com">orenelrad@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
To all that responded, thanks for the prompt response folks, your<br>
criticisms are well taken. Coming from Cland, one is inculcated with<br>
the notion that if the programmer wants to shoot himself in the foot<br>
the language ought not to prevent that (or even should return him a<br>
loaded magnum with the safety off and the hair-trigger pulled). My<br>
apologies for not immediately grokking the cultural difference in<br>
pytown.<br>
<br>
With that said, let me at least offer a token defense of my position.<br>
By way of motivation, I wrote that email after copying/pasting the<br>
following a few times around a project until I wrote it into def<br>
SilentlyDelete() and its cousin SilentlyRmdir()<br>
<br>
""" code involving somefile """<br>
try:<br>
........os.remove(somefile)<br>
except:<br>
.......pass # The bloody search indexer has got the file and I<br>
can't delete it. Nothing to be done.<br>
<br>
Certainly the parade of horribles (bad files! corrupt data! syntax<br>
errors!) is a tad melodramatic. Either os.remove() succeeds or it<br>
doesn't and the execution path (in the estimation of this programmer,<br>
at least) is not at all impacted by whether it succeeds or fails. I<br>
know with certainty at compile time what exceptions might be raised<br>
and what the consequences of passing them are and there is no sense<br>
pestering the user or sweating over it. Nor can I see the logic, as<br>
was suggested, in writing "except OSError:" since (seems to me) mere<br>
surplusage -- it neither causes a semantic difference in the way the<br>
program runs nor provides anything useful to the reader.<br><br></blockquote><div><br>What if the user presses Ctrl-C to try to quit the program? Your bare except is catching the KeyboardInterrupts and ignoring them.<br>
</div></div>