On Dec 22, 2:57 am, "Russ P." <[EMAIL PROTECTED]> wrote: > I am baffled about why my exception messages are not displaying > properly. > > I have a class that represents physical scalars with units. If I type > > >>> 3 * s + 4 * m > > I should get something like this: > > scalar.InconsistentUnits: 3 s, 4 m > > to show that seconds cannot be added to meters. Instead, the message > is broken up into individual characters, like this: > > scalar.InconsistentUnits: ('3', ' ', 's', ',', ' ', '4', ' ', 'm') > > This worked correctly for months, so I don't understand what went > wrong. I am using version 2.5.1 on a Dell workstation with Red Hat > Enterprise WS Linux. > > As far as I can tell, I am doing everything "by the book." Here is my > exception class: > > class InconsistentUnits(Exception): > def __init__(self, args=""): self.args = args > > and here is my instantiation of it: > > raise scalar.InconsistentUnits, str(self) + ", " + str(other) > > I've tried various little changes, but nothing seems to make any > difference. Has anyone else noticed this sort of behavior? Thanks. > > By the way, my scalar class is available for free > fromhttp://RussP.us/scalar.htm > . A complete user guide is available. Check it out. I think you'll > like it.
The problem is in the InconsistentUnits Exception. It seems that the act of: self.args = 'Some String' would break the string into chars, possibly because self.args think 'Some String' is a tuple of some sort. Change the exception into this: class InconsistentUnits(Exception): def __init__(self, args=""): self.args = (args,) # Python have an odd (read: broken) singleton implementation # single member tuple must have a comma behind it -- http://mail.python.org/mailman/listinfo/python-list