[Baypiggies] Stylin' in Python..
Glen Jarvis
glen at glenjarvis.com
Fri Jan 4 21:40:31 CET 2008
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 ;)
Since my last BayPiggies meeting, and an awesome conversation with
JJ, I have reverently adopted PEP-8 (http://www.python.org/dev/peps/
pep-0008/) 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.
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.
I use the example given in Learning Python (http://www.oreilly.com/
catalog/lpython/) by Mark Lutz for creating my own exception objects.
However, pychecker gives me the following warning that I am catching
a non-exception object:
> Warnings...
>
> demo.py:23: Catching a non-Exception object (General)
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?
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).
Cheers,
Glen
--
415-680-3964
glen at glenjarvis.com
http://www.glenjarvis.com
"You must be the change you wish to see in the world." -M. Gandhi
class General: pass
class Specific1(General): pass
class Specific2(General): pass
def raiser0():
X = General() # Raise superclass instance
raise X
def raiser1():
X = Specific1() # Raise subclass instance
raise X
def raiser2():
X = Specific2() # Raise different subclass instance
raise X
for func in (raiser0, raiser1, raiser2):
try:
func()
except General: # Match General or any subclass of it
import sys
print 'caught:', sys.exc_info()[0]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/baypiggies/attachments/20080104/9ef7a8fd/attachment.htm
More information about the Baypiggies
mailing list