[Tutor] random.choice()

John Fouhy john at fouhy.net
Thu Jul 3 03:26:03 CEST 2008


On 03/07/2008, Alan Gauld <alan.gauld at btinternet.com> wrote:
>  "John Fouhy" <john at fouhy.net> wrote
> > you can instead say:
> >
> > try:
> >   foo()
> > except TypeError:
> >   # do something else
>  This makes slightly more sense, although a TypeError seems a bit
>  too vague, if it had bveen a CallableError then I'd say fine. With
>  TypeError we have a much wider chance of a problem, particularly
>  if the callable takes parameters:

Well, I'm going by something I recall reading a while ago.  TypeError
is just what you get now if you try to call something that is not
callable.  Maybe things will change?

There's some discussion here which you could read:
http://mail.python.org/pipermail/python-3000/2006-July/002619.html

(and, of course, you could always put 'callable = lambda x: hasattr(x,
"__call__")' in some utility module)

-- 
John.


More information about the Tutor mailing list