Question about raise and exceptions.

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Thu Mar 1 03:14:43 EST 2007


On 1 mar, 04:46, Daniel Klein <danielklei... at gmail.com> wrote:
> On Wed, 28 Feb 2007 22:03:13 +0100, Bruno Desthuilliers
>
>
>
> <bdesth.quelquech... at free.quelquepart.fr> wrote:
> >Daniel Klein a écrit :
> >> The arguments for TransitionError must be a tuple,
>
> >Err...
>
> >> eg:
>
> >> msg = "Going to error state %d from state %d" % (self.curr_state,
> >> newstate)
> >> raise TransitionError(self, curr_state, newstate, msg)
>
> >Where did you see a tuple here ? You're code is *calling*
> >TransitionError, passing it the needed arguments.
>
> >Note that it's the correct syntax - but not the correct explanation !-)
>
> My bad :-(
>
> Thanks for setting me straight. I had (wrongly) thought that the stuff
> inside of () was a tuple.

For the record, it's the ',' that makes the tuple.  The () are  (in
this context) the call operator.


>>> t = 1, 2, 3
>>> t
(1, 2, 3)
>>> type(t)
<type 'tuple'>
>>> t2 = 1,
>>> t2
(1,)
>>> def toto():
>>>     return "it's me"
...
>>> toto
<function toto at 0xb7d18c34>
>>> toto()
"it's me"
>>>






More information about the Python-list mailing list