Re: exception message output problem

2007-12-23 Thread Florian Diesch
Lie <[EMAIL PROTECTED]> wrote: > # Python have an odd (read: broken) singleton implementation > # single member tuple must have a comma behind it Otherwise (1+2)+(3+4) would evaluate to (3, 7) instead of 10. Florian --

Re: exception message output problem

2007-12-22 Thread Russ P.
On Dec 22, 5:34 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Russ P. wrote: > > Actually, the parens aren't needed, so this works too: > > > def __init__(self, args=""): self.args = args, > > > The trailing comma wasn't necessary a while back (pre 2.5?), so > > something in Python must have c

Re: exception message output problem

2007-12-22 Thread Lie
On Dec 23, 4:30 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Lie a écrit : > > > PPS: Actually, what makes a tuple is both the parens and the comma, > > Nope, it's definively the comma. You can check the language's grammar, > it's part of the doc. Or just test FWIW: > > Python 2.4.3 (#1, Ma

Re: exception message output problem

2007-12-22 Thread Bruno Desthuilliers
Lie a écrit : > On Dec 22, 6:18 am, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > >>Lie a écrit : >>(snip) >> >> >>># Python have an odd (read: broken) singleton implementation >>># single member tuple must have a comma behind it >> >>You may call it weird or even a wart if you want, but give

Re: exception message output problem

2007-12-22 Thread Bruno Desthuilliers
Lie a écrit : > PPS: Actually, what makes a tuple is both the parens and the comma, Nope, it's definively the comma. You can check the language's grammar, it's part of the doc. Or just test FWIW: Python 2.4.3 (#1, Mar 12 2007, 23:32:01) [GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pi

Re: exception message output problem

2007-12-22 Thread Mel
Lie wrote: > PPS: Actually, what makes a tuple is both the parens and the comma, > with comma as the minimum signifier, inspect this: "str(a) + > str((a,b,c))", you have to use the double parens, one to make the > tuple and the other as part of the str. This harmless little case > gives error if do

Re: exception message output problem

2007-12-22 Thread Fredrik Lundh
Russ P. wrote: > Actually, the parens aren't needed, so this works too: > > def __init__(self, args=""): self.args = args, > > The trailing comma wasn't necessary a while back (pre 2.5?), so > something in Python must have changed. I'd say that it looks a bit > cleaner without the trailing c

Re: exception message output problem

2007-12-22 Thread Lie
PPS: Actually, what makes a tuple is both the parens and the comma, with comma as the minimum signifier, inspect this: "str(a) + str((a,b,c))", you have to use the double parens, one to make the tuple and the other as part of the str. This harmless little case gives error if done without the double

Re: exception message output problem

2007-12-22 Thread Lie
On Dec 22, 6:18 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Lie a écrit : > (snip) > > > # Python have an odd (read: broken) singleton implementation > > # single member tuple must have a comma behind it > > You may call it weird or even a wart if you want, but given that what > makes the

Re: exception message output problem

2007-12-21 Thread Russ P.
On Dec 21, 2:58 pm, Lie <[EMAIL PROTECTED]> wrote: > 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

Re: exception message output problem

2007-12-21 Thread Bruno Desthuilliers
Lie a écrit : (snip) > # Python have an odd (read: broken) singleton implementation > # single member tuple must have a comma behind it You may call it weird or even a wart if you want, but given that what makes the tuple is the comma - not the parens[1] -, it is _not_ broken. [1] with the excep

Re: exception message output problem

2007-12-21 Thread Lie
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:

exception message output problem

2007-12-21 Thread Russ P.
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 m