On Thu, Jan 8, 2009 at 2:21 PM, wesley chun <span dir="ltr">&lt;<a href="mailto:wescpy@gmail.com">wescpy@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
except:<br>
 &nbsp; &nbsp;pass<br>
<br>
try not to code these 2 lines in anything that you do because it will<br>
come back to haunt you when something is not working right but you<br>
can&#39;t find any errors. that&#39;s because this code masks and throws away<br>
everything!!<br>
<br>
if you are guaranteed that the strings all contain valid integers,<br>
then you don&#39;t have to worry about problems calling int().<br>
</blockquote><div><br>OP said we couldn&#39;t be sure that all rows would have the same number of elements; I&#39;m afraid I extrapolated that we also might not be sure they were all integers (or, I should say, strings representing integers...), so there are two potential error types: IndexError and ValueError.&nbsp; I assumed that if either one occurred, we would want to leave that particular list member (if it exists) as-is (hence the pass).<br>
<br>I see three ways around this: <br>- test each list for length, and each member for integer-ness, before casting anything; <br>- catch the exception, test to see whether it&#39;s an IndexError or a ValueError, and if not then do something; <br>
- print/log every exception.&nbsp; <br><br>The first one violates &quot;It&#39;s better to ask forgiveness than to ask permission&quot; (and it&#39;s slow), the second  one&#39;s a pain in the butt; the third one gets slow if LoL is large and has many non-standard members.&nbsp; Is there a fourth way?<br>
<br>Actually, I&#39;m asking because I&#39;ve run into similar situations and been dissatisfied with my own solution.&nbsp; Generally, if there are two or more &quot;acceptable&quot; errors that you can foresee, but you still want to catch any others, what&#39;s an elegant, readable,&nbsp; and computationally-cheap way to do it?&nbsp; Maybe a dictionary of exceptions...?<br>
</div></div><br>-- <br><a href="http://www.fsrtechnologies.com">www.fsrtechnologies.com</a><br>