[Baypiggies] Stylin' a big Thank You!
Glen Jarvis
glen at glenjarvis.com
Sun Jan 6 19:33:58 CET 2008
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.
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:
Chad Netzer gives me a great link to the Python Library (http://
docs.python.org/lib/module-exceptions.html#l2h-96), and explains how
rules have tightened up so that: isinstance(myexception, Exception)
== True.
Chris Clark gives me some template-code he uses that I can keep handy.
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:
BaseException - An exception, but not necessarily an error
Exception(BaseException) - An error
StandardError(Exception) - Generic error
ArithmeticError(Exception) - Bad math
LookupError(Exception) - Indexing error
EnvironmentError(Exception) - Something outside python
That gives me enough understanding so that when I read the library
documents, I can understand what I'm reading from context.
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.
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*..
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!
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
On Jan 4, 2008, at 12:40 PM, Glen Jarvis wrote:
> 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]
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/baypiggies/attachments/20080106/3bef6ad3/attachment.htm
More information about the Baypiggies
mailing list