<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
I hate to sound like a broken record, but I find the BayPIGgies group to be incredible!!! In my job, we never even used pychecker. Last month, I had learned about a PEP-8 style checking script - and I hadn't even known about PEP-8 before. I now routinely use a 'check' script that calls pychecker and then the PEP-8 script.<div><br class="webkit-block-placeholder"></div><div>It was only though these new practices that I discovered that I was not using exception handling in a forward-compatible manner (thus the Stylin' emails I recently sent). I had thought maybe pychecker might have been outdated or buggy and that this picky warning wasn't relevant. It turns out, however, because of the awesomness of BayPIGgies, I discover the impact of that warning:</div><div><br></div><div>Chad Netzer gives me a great link to the Python Library (<a href="http://docs.python.org/lib/module-exceptions.html#l2h-96">http://docs.python.org/lib/module-exceptions.html#l2h-96</a>), and explains how rules have tightened up so that: isinstance(myexception, Exception) == True.</div><div><br class="webkit-block-placeholder"></div><div>Chris Clark gives me some template-code he uses that I can keep handy.</div><div><br class="webkit-block-placeholder"></div><div>And, Jeff Younker gives me an excellent response, listing the broad categories of exceptions -- Exactly what a three month noob to python like me needed:</div><div><br class="webkit-block-placeholder"></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: 12.0px Helvetica">BaseException - An exception, but not necessarily an error</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Exception(BaseException) - An error</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: 12.0px Helvetica">StandardError(Exception) - Generic error</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: 12.0px Helvetica">ArithmeticError(Exception) - Bad math</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: 12.0px Helvetica">LookupError(Exception) - Indexing error</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: 12.0px Helvetica">EnvironmentError(Exception) - Something outside python</font></div></div><div><br class="webkit-block-placeholder"></div><div>That gives me enough understanding so that when I read the library documents, I can understand what I'm reading from context.</div><div><br class="webkit-block-placeholder"></div><div>In my job, we are pushing and pushing for code-reviews. We are trying to adopt standards like PEP-8. I'm not sure if this will ever be a company policy though. </div><div><br class="webkit-block-placeholder"></div><div>Our business finds that extra things like this are a waste of time and therefore resources. We have to get code out the door quickly. They aren't technical at all and don't see how we would have to re-write code (like above) in the future if we didn't spend the time getting it right the first time... And, with QA resources, and company processes, this balloons so quickly and wastes so much MORE time in the future... *sigh*..</div><div><br class="webkit-block-placeholder"></div><div>With BayPIGgies and a little proactivity on my part, I can fill in the cracks as best as I can. You guys (generic for guys and gals) really are AWESOME!</div><div><br></div><div>Cheers,</div><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div><div>Glen</div><div><div><div><div> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">--</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">415-680-3964</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:glen@glenjarvis.com">glen@glenjarvis.com</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://www.glenjarvis.com">http://www.glenjarvis.com</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">"You must be the change you wish to see in the world." -M. Gandhi</div><br class="Apple-interchange-newline"></span></span> </div><br><div><div>On Jan 4, 2008, at 12:40 PM, Glen Jarvis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"> <div>I've reached the level as a Python noob, where instead of struggling to get it to work, I'm struggling with doing things with style ;)</div><div><br class="webkit-block-placeholder"></div><div>Since my last BayPiggies meeting, and an awesome conversation with JJ, I have reverently adopted PEP-8 (<a href="http://www.python.org/dev/peps/pep-0008/">http://www.python.org/dev/peps/pep-0008/</a>) as a standard for all of my code. And, I've passed around the PEP-8 style guide in my office. Some of my peers are adopting it too.</div><div><br class="webkit-block-placeholder"></div><div>However, now, I come to some more subtle style questions. I regularly use pychecker and a PEP-8 checking script generously contributed to me from my last questions/discussion on style. </div><div><br class="webkit-block-placeholder"></div><div>I use the example given in Learning Python (<a href="http://www.oreilly.com/catalog/lpython/">http://www.oreilly.com/catalog/lpython/</a>) by Mark Lutz for creating my own exception objects. However, pychecker gives me the following warning that I am catching a non-exception object:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">&gt; Warnings...</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">&gt;  </font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">&gt; demo.py:23: Catching a non-Exception object (General)</font></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; "> </font></p></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br class="webkit-block-placeholder"></span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;">The sample code (from Learning Python) is included below my signature. My question is: Do I need to inherit a most-generic exception class? Or, is a non-exception class sufficient? </span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br class="webkit-block-placeholder"></span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;">What does everyone think? Is this agreed upon some where? This is a warning from pychecker only, not an error, so I expect it's not an agreed upon style.... What object would I inherit? I don't really know the exception class Hierarchy (although I should sit down and give it a quick review).</span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br class="webkit-block-placeholder"></span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br class="webkit-block-placeholder"></span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;">Cheers,</span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br class="webkit-block-placeholder"></span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br class="webkit-block-placeholder"></span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;">Glen</span></font></div><div> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">--</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">415-680-3964</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:glen@glenjarvis.com">glen@glenjarvis.com</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://www.glenjarvis.com">http://www.glenjarvis.com</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">"You must be the change you wish to see in the world." -M. Gandhi</div><br class="Apple-interchange-newline"></span></span> </div><br><div><span class="Apple-style-span" style="font-family: Arial; font-size: 13px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">class General: pass</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">class Specific1(General): pass</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">class Specific2(General): pass</font></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; "> </font></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">def raiser0():</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">    X = General()           # Raise superclass instance</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">    raise X</font></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; "> </font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; "> </font></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">def raiser1():</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">    X = Specific1()         # Raise subclass instance</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">    raise X</font></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; "> </font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; "> </font></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">def raiser2():</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">    X = Specific2()         # Raise different subclass instance</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">    raise X</font></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; "> </font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; "> </font></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">for func in (raiser0, raiser1, raiser2):</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">    try:</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">        func()</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">    except General:         # Match General or any subclass of it</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">        import sys</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Arial" size="4" style="font: normal normal normal 13px/normal Arial; ">        print 'caught:', sys.exc_info()[0]</font></div></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Baypiggies mailing list</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">To change your subscription options or unsubscribe:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://mail.python.org/mailman/listinfo/baypiggies">http://mail.python.org/mailman/listinfo/baypiggies</a></div> </blockquote></div><br></div></div></div></body></html>