Re: Exception Messages

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 09:00:15 -0700, Wanderer wrote: > How do you get Exceptions to print messages? I have an exception defined > like this > > class PvCamError(Exception): > def __init__(self, msg): > self.msg = msg Please don't invent yet another interface

Re: Exception Messages

2012-10-15 Thread Terry Reedy
On 10/15/2012 12:22 PM, John Gordon wrote: In MRAB writes: Why wasn't the message printed out? You didn't add a __str__ method: class PvCamError(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return self.msg Wouldn't PvCamError i

Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 1:34:24 PM UTC-4, MRAB wrote: > On 2012-10-15 18:18, Wanderer wrote: > > > On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote: > > > > > >> > > >> Yes, but you've put the message in msg, and Exception doesn't have that > > >> > > >> attribute. > > >> > > >

Re: Exception Messages

2012-10-15 Thread MRAB
On 2012-10-15 18:18, Wanderer wrote: On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote: Yes, but you've put the message in msg, and Exception doesn't have that attribute. That's weird. I got this Exception class definition idea from this post by Guido van Rostrum, Where he gives t

Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 1:18:52 PM UTC-4, Wanderer wrote: > On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote: > > > > > > > > Yes, but you've put the message in msg, and Exception doesn't have that > > > > > > attribute. > > > > > > > That's weird. I got this Exception cla

Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote: > > Yes, but you've put the message in msg, and Exception doesn't have that > > attribute. > That's weird. I got this Exception class definition idea from this post by Guido van Rostrum, Where he gives this main function to look like

Re: Exception Messages

2012-10-15 Thread Dave Angel
On 10/15/2012 12:34 PM, MRAB wrote: > On 2012-10-15 17:22, John Gordon wrote: >> In MRAB >> writes: >> >>> > Why wasn't the message printed out? >>> >>> You didn't add a __str__ method: >> >>> class PvCamError(Exception): >>> def __init__(self, msg): >>> self.msg = msg >>> def

Re: Exception Messages

2012-10-15 Thread MRAB
On 2012-10-15 17:22, John Gordon wrote: In MRAB writes: > Why wasn't the message printed out? You didn't add a __str__ method: class PvCamError(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return self.msg Wouldn't PvCamError inherit

Re: Exception Messages

2012-10-15 Thread John Gordon
In MRAB writes: > > Why wasn't the message printed out? > > You didn't add a __str__ method: > class PvCamError(Exception): > def __init__(self, msg): > self.msg = msg > def __str__(self): > return self.msg Wouldn't PvCamError inherit __str__() from Exception? --

Re: Exception Messages

2012-10-15 Thread MRAB
On 2012-10-15 17:00, Wanderer wrote: How do you get Exceptions to print messages? I have an exception defined like this class PvCamError(Exception): def __init__(self, msg): self.msg = msg But when the error is raised I get this: Traceback (most recent call last): File "C:\P

Exception Messages

2012-10-15 Thread Wanderer
How do you get Exceptions to print messages? I have an exception defined like this class PvCamError(Exception): def __init__(self, msg): self.msg = msg But when the error is raised I get this: Traceback (most recent call last): File "C:\Python27\lib\site-packages\ipython-0.12.1-p

RE: PEP8 compliance and exception messages ?

2010-12-08 Thread Gerald Britton
I'm a bit late to the discussion, but remembering that raise takes an expression, I can break it up like this: >>> raise ( ... Exception ( ... "Long " ... "exception " ... "text." ... ) ... ) Traceback (most recent call last): File "", line 3, in Exception: Long exception text Then, you can in

Re: PEP8 compliance and exception messages ?

2010-12-07 Thread shearichard
On Dec 7, 9:17 am, Andreas Waldenburger wrote: > On Mon, 6 Dec 2010 00:22:49 -0500 Andreas Waldenburger > wrote: > > > > > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert > > wrote: > > > > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > > > wrote: > > > > Hi - PEP8 says lines should not exceed 7

Re: PEP8 compliance and exception messages ?

2010-12-07 Thread shearichard
On Dec 6, 6:21 pm, Ben Finney wrote: > shearichard writes: > > Hi - PEP8 says lines should not exceed 79 characters in length > > (http://www.python.org/dev/peps/pep-0008/). > > > So if you've got some code that looks like this : > > > raise fooMod.fooException("Some message which is quite long")

Re: PEP8 compliance and exception messages ?

2010-12-06 Thread Andreas Waldenburger
On Mon, 6 Dec 2010 00:22:49 -0500 Andreas Waldenburger wrote: > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert > wrote: > > > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > > wrote: > > > Hi - PEP8 says lines should not exceed 79 characters in length > > > ( http://www.python.org/dev/peps/pep-

Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Steven D'Aprano
On Mon, 06 Dec 2010 06:15:06 +, Tim Harig wrote: >> But isn't explicit string literal concatenation better than implicit >> string literal concatenation? > > So add the "+", it really doesn't change it much. Perhaps not *much*, but it *may* change it a bit. Implicit concatenation of literal

Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Tim Harig
On 2010-12-06, Andreas Waldenburger wrote: > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert wrote: > >> On Sun, Dec 5, 2010 at 7:40 PM, shearichard >> wrote: >> > Hi - PEP8 says lines should not exceed 79 characters in length >> > ( http://www.python.org/dev/peps/pep-0008/ ). >> > >> > So if you

Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Andreas Waldenburger
On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert wrote: > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > wrote: > > Hi - PEP8 says lines should not exceed 79 characters in length > > ( http://www.python.org/dev/peps/pep-0008/ ). > > > > So if you've got some code that looks like this : > > > > rais

Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Ben Finney
shearichard writes: > Hi - PEP8 says lines should not exceed 79 characters in length > ( http://www.python.org/dev/peps/pep-0008/ ). > > So if you've got some code that looks like this : > > raise fooMod.fooException("Some message which is quite long") PEP 8 also says those names are poorly chos

Re: PEP8 compliance and exception messages ?

2010-12-05 Thread MRAB
On 06/12/2010 03:40, shearichard wrote: Hi - PEP8 says lines should not exceed 79 characters in length ( http://www.python.org/dev/peps/pep-0008/ ). So if you've got some code that looks like this : raise fooMod.fooException("Some message which is quite long") ... and assuming a certain amount

Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Chris Rebert
On Sun, Dec 5, 2010 at 7:40 PM, shearichard wrote: > Hi - PEP8 says lines should not exceed 79 characters in length > ( http://www.python.org/dev/peps/pep-0008/ ). > > So if you've got some code that looks like this : > > raise fooMod.fooException("Some message which is quite long") > > ... and as

PEP8 compliance and exception messages ?

2010-12-05 Thread shearichard
Hi - PEP8 says lines should not exceed 79 characters in length ( http://www.python.org/dev/peps/pep-0008/ ). So if you've got some code that looks like this : raise fooMod.fooException("Some message which is quite long") ... and assuming a certain amount of indenting you're going to break that g