<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<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><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; ">&gt;  </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; ">&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></body></html>